simplify subparser build logic
@@ -72,10 +72,9 @@ def cli_entry(*args):
mod = importlib.import_module('.{}'.format(h), 'kgtk.cli')
subp = mod.parser()
sub_parser = sub_parsers.add_parser(h, **subp)
- add_default_arguments(sub_parser) # call this before adding other arguments
subparser_lookup[h] = [mod, sub_parser]
- if "aliases" in subp:
- for alias in subp["aliases"]:
+ if 'aliases' in subp:
+ for alias in subp['aliases']:
subparser_lookup[alias] = [mod, sub_parser]
# add root level usage after sub-parsers are created
@@ -91,11 +90,10 @@ def cli_entry(*args):
cmd_args = pipe[0]
cmd_name = cmd_args[0]
- if cmd_name not in subparser_lookup:
- parser.parse_args(cmd_args) # This will generate the right error message
- sys.exit(1)
+ if cmd_name in subparser_lookup:
mod, sub_parser = subparser_lookup[cmd_name]
- if hasattr(mod, "add_arguments_extended"):
+ add_default_arguments(sub_parser) # call this before adding other arguments
+ if hasattr(mod, 'add_arguments_extended'):
mod.add_arguments_extended(sub_parser, parsed_shared_args)
else:
mod.add_arguments(sub_parser)
