diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-08-28 01:27:05 -0400 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-08-28 01:27:05 -0400 |
| commit | df703af969219665b7d672025bf9b26f75a76285 (patch) | |
| tree | 4843360faf9677cfb0c22d95f1ae0bd100561616 /cmd2 | |
| parent | 6b5065e77715c6bab45f3a57eb5b97e3cbe4b86d (diff) | |
| parent | 36b0b75265942fe375545beb7d2d8a2c5f6f63c4 (diff) | |
| download | cmd2-git-df703af969219665b7d672025bf9b26f75a76285.tar.gz | |
Merge branch 'master' into 2.0
Diffstat (limited to 'cmd2')
| -rw-r--r-- | cmd2/cmd2.py | 18 | ||||
| -rw-r--r-- | cmd2/decorators.py | 8 |
2 files changed, 13 insertions, 13 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 9cc75c83..730b0934 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -702,9 +702,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 @@ -2719,8 +2721,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_provider=_get_commands_aliases_and_macros_for_completion) @@ -2764,7 +2765,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_provider=_get_alias_completion_items, descriptive_header='Value') alias_delete_parser.add_argument('-a', '--all', action='store_true', help="delete all aliases") @@ -2792,7 +2793,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_provider=_get_alias_completion_items, descriptive_header='Value') @@ -2870,8 +2871,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_provider=_get_commands_aliases_and_macros_for_completion) @@ -2961,7 +2961,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_provider=_get_macro_completion_items, descriptive_header='Value') macro_delete_parser.add_argument('-a', '--all', action='store_true', help="delete all macros") @@ -2989,7 +2989,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_provider=_get_macro_completion_items, descriptive_header='Value') diff --git a/cmd2/decorators.py b/cmd2/decorators.py index d173334d..6bc57b90 100644 --- a/cmd2/decorators.py +++ b/cmd2/decorators.py @@ -35,7 +35,7 @@ def with_category(category: str) -> Callable: return cat_decorator ########################## -# The _parse_positionals and _swap_args decorators allow for additional positional args to be preserved +# The _parse_positionals and _arg_swap functions allow for additional positional args to be preserved # in cmd2 command functions/callables. As long as the 2-ple of arguments we expect to be there can be # found we can swap out the statement with each decorator's specific parameters ########################## @@ -276,9 +276,9 @@ def with_argparser(parser: argparse.ArgumentParser, *, :return: return value of command function :raises: Cmd2ArgparseError if argparse has error parsing command line """ - cmd2_app, statement = _parse_positionals(args) + cmd2_app, statement_arg = _parse_positionals(args) statement, parsed_arglist = cmd2_app.statement_parser.get_command_arg_list(command_name, - statement, + statement_arg, preserve_quotes) if ns_provider is None: @@ -311,7 +311,7 @@ def with_argparser(parser: argparse.ArgumentParser, *, if hasattr(ns, constants.NS_ATTR_SUBCMD_HANDLER): delattr(ns, constants.NS_ATTR_SUBCMD_HANDLER) - args_list = _arg_swap(args, statement, *new_args) + args_list = _arg_swap(args, statement_arg, *new_args) return func(*args_list, **kwargs) # argparser defaults the program name to sys.argv[0], but we want it to be the name of our command |
