From 00f23a6983d7fbfc1c6a70c865309f4e56b17501 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Tue, 31 Aug 2021 15:55:04 -0400 Subject: [PATCH] Unify command-line options and configuration This adds command-line options to the configuration, but not vice-versa. It will allow for greater flexibility when running this automatically without having to change any scripting. https://bugzilla.redhat.com/show_bug.cgi?id=1872467 Signed-off-by: Rob Crittenden --- man/man5/ipahealthcheck.conf.5 | 10 +++++++++- src/ipahealthcheck/core/core.py | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/man/man5/ipahealthcheck.conf.5 b/man/man5/ipahealthcheck.conf.5 index 50d55063..2cbff7d8 100644 --- a/man/man5/ipahealthcheck.conf.5 +++ b/man/man5/ipahealthcheck.conf.5 @@ -36,6 +36,14 @@ The following options are relevant for the server: .TP .B cert_expiration_days\fR The number of days left before a certificate expires to start displaying a warning. The default is 28. +.TP +All command\-line options may be include in the configuration file. Dashes must be converted to underscore for the configuration file, e.g. \-\-output\-type becomes output_type. All options, including those that don't make sense in a config file, like \-\-list\-sources, are allowed. Let the buyer beware. +.TP +The purpose of allowing command\-line options to be in the configuration file is for automation without having to tweak the automation script. For example, if you want the default output type to be human for the systemd timer automated runs, settting output_type=human in the configuration file will do this. Note that changing the default location of log files is not possible because the shipped timer executable has \-\-output\-file on the command\-line so will override the configuration file. +.TP +Options are first loaded from the configuration file and command\-line options are merged in, with the command\-line option having preference. The command\-line take precedence except where this is not possible. An example is if all=True is set in the configuration file, and the command\-line contains \-\-failures\-only, then only failures will be displayed. +.TP +Options that don't make sense for the configuration file include \-\-list\-sources and \-\-input\-file. .SH "FILES" .TP .I /etc/ipahealthcheck/ipahealthcheck.conf @@ -49,4 +57,4 @@ configuration file cert_expiration_days=7 .SH "SEE ALSO" -.BR ipa-healthcheck (8) +.BR ipa\-healthcheck (8) diff --git a/src/ipahealthcheck/core/core.py b/src/ipahealthcheck/core/core.py index 6fd36403..99a26b1e 100644 --- a/src/ipahealthcheck/core/core.py +++ b/src/ipahealthcheck/core/core.py @@ -266,7 +266,6 @@ def run_healthcheck(self): add_output_options(self.parser, self.output_registry) self.add_options() options = parse_options(self.parser) - self.options = options if options.version: for registry in self.entry_points: @@ -294,6 +293,12 @@ def run_healthcheck(self): if config is None: return 1 + # Unify config and options. One will be deprecated in the + # future. This way all cli options can be set in config instead. + config.merge(vars(options)) + self.options = config + options = config + # pylint: disable=assignment-from-none rval = self.pre_check() # pylint: enable=assignment-from-none