From ddac998671ed64c07af87feab7f3fd568bc76ce7 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Mon, 15 Jan 2018 00:08:28 -0500 Subject: Fixed @with_argument_decorator so that built-in help text is preserved --- cmd2.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd2.py b/cmd2.py index 045f1a39..c8682dc5 100755 --- a/cmd2.py +++ b/cmd2.py @@ -258,6 +258,7 @@ def parse_quoted_string(cmdline): lexed_arglist = temp_arglist return lexed_arglist + def with_argument_parser(argparser): """A decorator to alter a cmd2 method to populate its ``opts`` argument by parsing arguments with the given instance of @@ -293,6 +294,8 @@ def with_argument_list(func): def cmd_wrapper(self, cmdline): lexed_arglist = parse_quoted_string(cmdline) func(self, lexed_arglist) + + cmd_wrapper.__doc__ = func.__doc__ return cmd_wrapper @@ -1672,6 +1675,7 @@ a..b, a:b, a:, ..b by indices (inclusive) arg is string containing string arg is /regex/ matching regular expression regex""" argparser.add_argument('arg', nargs='*', help=_history_arg_help) + @with_argument_parser(argparser) def do_history(self, arglist, args): # If an argument was supplied, then retrieve partial contents of the history -- cgit v1.2.1 From 07e37b2d081161af32feb64890b1fd4236bf5f13 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Mon, 15 Jan 2018 00:27:06 -0500 Subject: Fixed do_history unit tests and implementation --- cmd2.py | 2 +- tests/conftest.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd2.py b/cmd2.py index c8682dc5..91e90def 100755 --- a/cmd2.py +++ b/cmd2.py @@ -1679,7 +1679,7 @@ arg is /regex/ matching regular expression regex""" @with_argument_parser(argparser) def do_history(self, arglist, args): # If an argument was supplied, then retrieve partial contents of the history - if arglist: + if args.arg: # If a character indicating a slice is present, retrieve a slice of the history arg = args.arg[0] if '..' in arg or ':' in arg: diff --git a/tests/conftest.py b/tests/conftest.py index 97116b48..21899f36 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,19 +20,20 @@ cmdenvironment help load pyscript run set shortcuts """ # Help text for the history command -HELP_HISTORY = """history [arg]: lists past commands issued +HELP_HISTORY = """usage: history [-h] [-s] [arg [arg ...]] - | no arg: list all - | arg is integer: list one history item, by index - | a..b, a:b, a:, ..b -> list history items by a span of indices (inclusive) - | arg is string: list all commands matching string search - | arg is /enclosed in forward-slashes/: regular expression search +list past commands issued -Usage: history [options] (limit on which commands to include) +positional arguments: + arg no arg list all + arg is integer by index + a..b, a:b, a:, ..b by indices (inclusive) + arg is string containing string + arg is /regex/ matching regular expression regex -Options: +optional arguments: -h, --help show this help message and exit - -s, --script Script format; no separation lines + -s, --script script format; no separation lines """ # Output from the shortcuts command with default built-in shortcuts -- cgit v1.2.1