summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-01 11:50:37 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-01 11:50:37 -0400
commit610aad33eb8fe1772480e98af8b255bd56dfe78c (patch)
treeb9dfb60fa0a60b438c8b8e31679f6df768f24665 /cmd2/cmd2.py
parent20f4a52399c5c1ee87ae57b9f082113663b20060 (diff)
parent93d40a4a486ae6121858f9fb7369ed272a768672 (diff)
downloadcmd2-git-610aad33eb8fe1772480e98af8b255bd56dfe78c.tar.gz
Merge branch 'quoted_args' of github.com:python-cmd2/cmd2 into quoted_args
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 83a5a7c8..1c8bb6b7 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
@@ -1717,7 +1720,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.
@@ -2565,18 +2568,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()
@@ -2887,7 +2891,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',
@@ -3235,6 +3239,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