summaryrefslogtreecommitdiff
path: root/cmd2/decorators.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-08-07 15:26:40 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-08-07 15:26:40 -0400
commit3ada4bd53925ca20fdeb16fa971814637dc42e4d (patch)
treecb8cbcf6595b797a35131fba7a94ad4f7afd463c /cmd2/decorators.py
parent2049496815bc0e46db2371f9173c0cef7496e706 (diff)
downloadcmd2-git-3ada4bd53925ca20fdeb16fa971814637dc42e4d.tar.gz
Moved code which copies subparser's settings to _register_subcommands().
Changed alias and macro commands to use as_subcommand_to() decorator. Updated CommandSet subcommand example to use help and description text.
Diffstat (limited to 'cmd2/decorators.py')
-rw-r--r--cmd2/decorators.py28
1 files changed, 5 insertions, 23 deletions
diff --git a/cmd2/decorators.py b/cmd2/decorators.py
index 9981ca94..0dda3485 100644
--- a/cmd2/decorators.py
+++ b/cmd2/decorators.py
@@ -352,32 +352,14 @@ def as_subcommand_to(command: str,
setattr(func, constants.CMD_ATTR_ARGPARSER, parser)
setattr(func, constants.SUBCMD_ATTR_NAME, subcommand)
- # Dictionary of arguments which will be passed to ArgumentParser.add_subparser()
- parser_args = dict()
-
- # parser is set as the parent to the one being created by ArgumentParser.add_parser().
- # argparse only copies actions (arguments) from a parent and not the following settings.
- # To retain these settings, we will copy them from parser and pass them as ArgumentParser
- # constructor arguments to add_parser().
- parser_args['prog'] = parser.prog
- parser_args['usage'] = parser.usage
- parser_args['description'] = parser.description
- parser_args['epilog'] = parser.epilog
- parser_args['formatter_class'] = parser.formatter_class
- parser_args['prefix_chars'] = parser.prefix_chars
- parser_args['fromfile_prefix_chars'] = parser.fromfile_prefix_chars
- parser_args['argument_default'] = parser.argument_default
- parser_args['conflict_handler'] = parser.conflict_handler
- parser_args['add_help'] = parser.add_help
- parser_args['allow_abbrev'] = parser.allow_abbrev
-
- # Add remaining arguments specific to add_parser()
+ # Keyword arguments for ArgumentParser.add_subparser()
+ add_parser_kwargs = dict()
if help is not None:
- parser_args['help'] = help
+ add_parser_kwargs['help'] = help
if aliases is not None:
- parser_args['aliases'] = aliases[:]
+ add_parser_kwargs['aliases'] = aliases[:]
- setattr(func, constants.SUBCMD_ATTR_PARSER_ARGS, parser_args)
+ setattr(func, constants.SUBCMD_ATTR_ADD_PARSER_KWARGS, add_parser_kwargs)
return func