kas: Simplify plugin lookup
By storing plugins in a dictionary indexed by plugin name rather than a list, we can simplify plugin lookup and remove the undocumented need for a plugin's run() method to return True when it has matched the given command. The command will be rejected by the argument parser if it does not match one of the plugin names so we do not need to handle failure to lookup the plugin in the dictionary. Signed-off-by: Paul Barker <pbarker@konsulko.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
12
kas/kas.py
12
kas/kas.py
@@ -134,7 +134,7 @@ def kas_get_argparser():
|
||||
for ext_plugin in pkg_resources.iter_entry_points('kas.plugins'):
|
||||
ext_plugin.load()
|
||||
|
||||
for plugin in getattr(kasplugin, 'plugins', []):
|
||||
for plugin in getattr(kasplugin, 'plugins', {}).values():
|
||||
plugin_parser = subparser.add_parser(plugin.name, help=plugin.helpmsg)
|
||||
setup_parser_common_args(plugin_parser)
|
||||
plugin.setup_parser(plugin_parser)
|
||||
@@ -162,11 +162,11 @@ def kas(argv):
|
||||
loop.add_signal_handler(sig, interruption)
|
||||
atexit.register(_atexit_handler)
|
||||
|
||||
for plugin in getattr(kasplugin, 'plugins', []):
|
||||
if plugin().run(args):
|
||||
return 0
|
||||
|
||||
parser.print_help()
|
||||
if args.cmd:
|
||||
plugin = getattr(kasplugin, 'plugins', {})[args.cmd]
|
||||
plugin().run(args)
|
||||
else:
|
||||
parser.print_help()
|
||||
|
||||
|
||||
def main():
|
||||
|
Reference in New Issue
Block a user