diff options
author | Pavel Moravec <pmoravec@redhat.com> | 2023-04-17 08:06:43 +0200 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2023-04-25 09:17:41 -0400 |
commit | 0bd7102e19de897f1d273d4b857a1b050db8e2ed (patch) | |
tree | 708a5ca06e8cceb551f8178b335c90b2b14d4fbb | |
parent | d8794b95549fe82a68921c2e4a2daad6e85f82ff (diff) | |
download | sos-0bd7102e19de897f1d273d4b857a1b050db8e2ed.tar.gz |
[report] Honour -o/-e/-n from cmdline over preset
When preset disables a plugin that user wants to manually enable,
current merging of options ends up with -e PLUG -n PLUG which makes the
plugin still disabled.
apply_options_from_cmdline method must remove the preset options for any
plugin that interfere with cmdline options for the plugin.
Resolves: #3195
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r-- | sos/component.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/sos/component.py b/sos/component.py index a5a3fb1f..8c62af34 100644 --- a/sos/component.py +++ b/sos/component.py @@ -218,9 +218,21 @@ class SoSComponent(): # set all values back to their normal default codict = cmdopts.dict(preset_filter=False) for opt, val in codict.items(): - if opt not in cmdopts.arg_defaults.keys(): + if opt not in cmdopts.arg_defaults.keys() or val in [None, [], '']: continue - if val not in [None, [], ''] and val != opts.arg_defaults[opt]: + # A plugin that is [enabled|disabled|only] in cmdopts must + # overwrite these three options of itself in opts - reset it first + if opt in ["enable_plugins", "skip_plugins", "only_plugins"]: + for oopt in ["enable_plugins", "skip_plugins", "only_plugins"]: + common = set(val) & set(getattr(opts, oopt)) + # common has all plugins that are in this combination of + # "[-e|-o|-n] plug" of cmdopts & "[-e|-o|-n] plug" of opts + # so remove those plugins from this [-e|-o|-n] opts + if common: + setattr(opts, oopt, [x for x in getattr(opts, oopt) + if x not in common]) + + if val != opts.arg_defaults[opt]: setattr(opts, opt, val) return opts |