From 11e3eabbff8f80c9c85c04b7e9d6071246856bcf Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Thu, 23 Aug 2018 13:12:46 -0400 Subject: Removed Statement.args since it was redundant. Replaced with already parsed list of args with quotes preserved. --- cmd2/cmd2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd2/cmd2.py') diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 83a5a7c8..be672465 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1717,7 +1717,7 @@ class Cmd(cmd.Cmd): :return: tuple containing (command, args, line) """ statement = self.statement_parser.parse_command_only(line) - return statement.command, statement.args, statement.command_and_args + return statement.command, statement, statement.command_and_args def onecmd_plus_hooks(self, line: str) -> bool: """Top-level function called by cmdloop() to handle parsing a line and running the command and all of its hooks. -- cgit v1.2.1 From 2b2110ad24b64d022128051169a3515257922c8f Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Thu, 23 Aug 2018 23:36:42 -0400 Subject: Added way of returning a non-zero exit code to the shell --- cmd2/cmd2.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cmd2/cmd2.py') diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 58972232..a17e128f 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -523,6 +523,9 @@ class Cmd(cmd.Cmd): # This boolean flag determines whether or not the cmd2 application can interact with the clipboard self.can_clip = can_clip + # This determines if a non-zero exit code should be used when exiting the application + self.exit_code = None + # ----- Methods related to presenting output to the user ----- @property @@ -3227,6 +3230,9 @@ Script should contain one command per line, just like command would be typed in func() self.postloop() + if self.exit_code is not None: + sys.exit(self.exit_code) + ### # # plugin related functions -- cgit v1.2.1 From d953fb28d9afc82098512b0bd5f99104a9c193b8 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Fri, 24 Aug 2018 11:10:03 -0400 Subject: ACHelpFormatter now inherits from argparse.RawTextHelpFormatter to make it easier to format help/description text --- cmd2/cmd2.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'cmd2/cmd2.py') diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 58972232..2303e86c 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -2553,18 +2553,19 @@ Usage: Usage: unalias [-a] name [name ...] else: raise LookupError("Parameter '%s' not supported (type 'set' for list of parameters)." % param) - set_parser = ACArgumentParser(formatter_class=argparse.RawTextHelpFormatter) + set_description = "Sets a settable parameter or shows current settings of parameters.\n" + set_description += "\n" + set_description += "Accepts abbreviated parameter names so long as there is no ambiguity.\n" + set_description += "Call without arguments for a list of settable parameters with their values." + + set_parser = ACArgumentParser(description=set_description) set_parser.add_argument('-a', '--all', action='store_true', help='display read-only settings as well') set_parser.add_argument('-l', '--long', action='store_true', help='describe function of parameter') set_parser.add_argument('settable', nargs=(0, 2), help='[param_name] [value]') @with_argparser(set_parser) def do_set(self, args: argparse.Namespace) -> None: - """Sets a settable parameter or shows current settings of parameters. - - Accepts abbreviated parameter names so long as there is no ambiguity. - Call without arguments for a list of settable parameters with their values. - """ + """Sets a settable parameter or shows current settings of parameters""" try: param_name, val = args.settable val = val.strip() @@ -2879,7 +2880,7 @@ Paths or arguments that contain spaces must be enclosed in quotes embed(banner1=banner, exit_msg=exit_msg) load_ipy(bridge) - history_parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) + history_parser = ACArgumentParser() history_parser_group = history_parser.add_mutually_exclusive_group() history_parser_group.add_argument('-r', '--run', action='store_true', help='run selected history items') history_parser_group.add_argument('-e', '--edit', action='store_true', -- cgit v1.2.1