diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2019-03-20 11:57:37 +0000 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2019-03-20 11:57:37 +0000 |
commit | 67f8b673ac457db097f50665d0702573d14b1be1 (patch) | |
tree | f4c6e15a4778c0b7d9bf6ac290b61c350472f434 | |
parent | aeade1c831eb700c7fab3ae5aa3e1d6ef9f0c483 (diff) | |
download | sos-67f8b673ac457db097f50665d0702573d14b1be1.tar.gz |
[sosreport] handle non-valued and counter options in sos.conf
Command line arguments that are non-valued ("store_true"), or that
have counter semantics need special handling when read from the
configuration file (since optionless values *do* have an explicit
value in the file, in order to meet .ini file structure, and since
counter values are represented in the file as an integer).
Process these options specially and return them in a form that is
correctly parsed by the ArgumentParser.
Related: #1530
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/__init__.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/sos/__init__.py b/sos/__init__.py index 491d801f..b0c10f4a 100644 --- a/sos/__init__.py +++ b/sos/__init__.py @@ -209,6 +209,25 @@ class SoSOptions(object): return opts @classmethod + def _opt_to_args(cls, opt, val): + """Convert a named option and optional value to command line + argument notation, correctly handling options that take + no value or that have special representations (e.g. verify + and verbose). + """ + no_value = ( + "alloptions", "all-logs", "batch", "build", "debug", + "experimental", "list-plugins", "list-presets", "list-profiles", + "noreport", "quiet", "verify" + ) + count = ("verbose",) + if opt in no_value: + return ["--%s" % opt] + if opt in count: + return ["--%s" % opt for d in range(0, int(val))] + return ["--" + opt + "=" + val] + + @classmethod def from_file(cls, argparser, config_file, is_default=True): opts = SoSOptions() config = ConfigParser() @@ -226,8 +245,7 @@ class SoSOptions(object): if config.has_section("general"): optlist = [] for opt, val in config.items("general"): - # assume just long options are specified so prefix them by "--" - optlist.append("--" + opt + "=" + val) + optlist.extend(SoSOptions._opt_to_args(opt, val)) opts._merge_opts(argparser.parse_args(optlist), is_default) if config.has_option("plugins", "disable"): |