Skip to content

Commit

Permalink
[report] Honour -o/-e/-n from cmdline over preset
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pmoravec authored and TurboTurtle committed Apr 25, 2023
1 parent d8794b9 commit 0bd7102
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions sos/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,21 @@ def apply_options_from_cmdline(self, opts):
# 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
Expand Down

0 comments on commit 0bd7102

Please sign in to comment.