summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-08-27 20:56:56 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-08-27 23:17:05 -0400
commite3ed15ed375674729d65e4f594a8958ea91ae684 (patch)
treea05524c8f7fc3c56776e32648b5808252c7e6d51 /cmd2
parent47f8652fa467b2d140b1097b3167f968b0188451 (diff)
downloadcmd2-git-e3ed15ed375674729d65e4f594a8958ea91ae684.tar.gz
Fixed issue where subcommand added with @as_subcommand_to decorator did not display help when called with -h/--help.
'add_help=False' no longer has to be passed to parsers used in @as_subcommand_to decorator.
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/cmd2.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 103508c5..d768085a 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -701,9 +701,11 @@ class Cmd(cmd.Cmd):
add_parser_kwargs['fromfile_prefix_chars'] = subcmd_parser.fromfile_prefix_chars
add_parser_kwargs['argument_default'] = subcmd_parser.argument_default
add_parser_kwargs['conflict_handler'] = subcmd_parser.conflict_handler
- add_parser_kwargs['add_help'] = subcmd_parser.add_help
add_parser_kwargs['allow_abbrev'] = subcmd_parser.allow_abbrev
+ # Set add_help to False and use whatever help option subcmd_parser already has
+ add_parser_kwargs['add_help'] = False
+
attached_parser = action.add_parser(subcommand_name, **add_parser_kwargs)
setattr(attached_parser, constants.PARSER_ATTR_COMMANDSET, cmdset)
break
@@ -2703,8 +2705,7 @@ class Cmd(cmd.Cmd):
" alias create show_log !cat \"log file.txt\"\n"
" alias create save_results print_results \">\" out.txt\n")
- alias_create_parser = DEFAULT_ARGUMENT_PARSER(add_help=False, description=alias_create_description,
- epilog=alias_create_epilog)
+ alias_create_parser = DEFAULT_ARGUMENT_PARSER(description=alias_create_description, epilog=alias_create_epilog)
alias_create_parser.add_argument('name', help='name of this alias')
alias_create_parser.add_argument('command', help='what the alias resolves to',
choices_method=_get_commands_aliases_and_macros_for_completion)
@@ -2748,7 +2749,7 @@ class Cmd(cmd.Cmd):
alias_delete_help = "delete aliases"
alias_delete_description = "Delete specified aliases or all aliases if --all is used"
- alias_delete_parser = DEFAULT_ARGUMENT_PARSER(add_help=False, description=alias_delete_description)
+ alias_delete_parser = DEFAULT_ARGUMENT_PARSER(description=alias_delete_description)
alias_delete_parser.add_argument('names', nargs=argparse.ZERO_OR_MORE, help='alias(es) to delete',
choices_method=_get_alias_completion_items, descriptive_header='Value')
alias_delete_parser.add_argument('-a', '--all', action='store_true', help="delete all aliases")
@@ -2776,7 +2777,7 @@ class Cmd(cmd.Cmd):
"\n"
"Without arguments, all aliases will be listed.")
- alias_list_parser = DEFAULT_ARGUMENT_PARSER(add_help=False, description=alias_list_description)
+ alias_list_parser = DEFAULT_ARGUMENT_PARSER(description=alias_list_description)
alias_list_parser.add_argument('names', nargs=argparse.ZERO_OR_MORE, help='alias(es) to list',
choices_method=_get_alias_completion_items, descriptive_header='Value')
@@ -2854,8 +2855,7 @@ class Cmd(cmd.Cmd):
" Because macros do not resolve until after hitting Enter, tab completion\n"
" will only complete paths while typing a macro.")
- macro_create_parser = DEFAULT_ARGUMENT_PARSER(add_help=False, description=macro_create_description,
- epilog=macro_create_epilog)
+ macro_create_parser = DEFAULT_ARGUMENT_PARSER(description=macro_create_description, epilog=macro_create_epilog)
macro_create_parser.add_argument('name', help='name of this macro')
macro_create_parser.add_argument('command', help='what the macro resolves to',
choices_method=_get_commands_aliases_and_macros_for_completion)
@@ -2945,7 +2945,7 @@ class Cmd(cmd.Cmd):
# macro -> delete
macro_delete_help = "delete macros"
macro_delete_description = "Delete specified macros or all macros if --all is used"
- macro_delete_parser = DEFAULT_ARGUMENT_PARSER(add_help=False, description=macro_delete_description)
+ macro_delete_parser = DEFAULT_ARGUMENT_PARSER(description=macro_delete_description)
macro_delete_parser.add_argument('names', nargs=argparse.ZERO_OR_MORE, help='macro(s) to delete',
choices_method=_get_macro_completion_items, descriptive_header='Value')
macro_delete_parser.add_argument('-a', '--all', action='store_true', help="delete all macros")
@@ -2973,7 +2973,7 @@ class Cmd(cmd.Cmd):
"\n"
"Without arguments, all macros will be listed.")
- macro_list_parser = DEFAULT_ARGUMENT_PARSER(add_help=False, description=macro_list_description)
+ macro_list_parser = DEFAULT_ARGUMENT_PARSER(description=macro_list_description)
macro_list_parser.add_argument('names', nargs=argparse.ZERO_OR_MORE, help='macro(s) to list',
choices_method=_get_macro_completion_items, descriptive_header='Value')