summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2019-12-05 22:45:05 -0800
committerkotfu <kotfu@kotfu.net>2019-12-05 22:45:05 -0800
commit10b844809e3a9500274dc4af4e780708975ba905 (patch)
tree500638d447a3b2cc51937c80a21aa5c61031897b /cmd2/cmd2.py
parent10da7317721cd091af9e235d33c81b8c6e93e450 (diff)
parent367f9f156d58f434a57345515306b6d14e9f4e80 (diff)
downloadcmd2-git-10b844809e3a9500274dc4af4e780708975ba905.tar.gz
Merge branch 'master' into generating_output_docs
# Conflicts: # cmd2/ansi.py
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index c5b058a0..b025043e 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -455,7 +455,7 @@ class Cmd(cmd.Cmd):
"""
return ansi.strip_ansi(self.prompt)
- def poutput(self, msg: Any, *, end: str = '\n') -> None:
+ def poutput(self, msg: Any = '', *, end: str = '\n') -> None:
"""Print message to self.stdout and appends a newline by default
Also handles BrokenPipeError exceptions for when a commands's output has
@@ -476,8 +476,8 @@ class Cmd(cmd.Cmd):
if self.broken_pipe_warning:
sys.stderr.write(self.broken_pipe_warning)
- @staticmethod
- def perror(msg: Any, *, end: str = '\n', apply_style: bool = True) -> None:
+ # noinspection PyMethodMayBeStatic
+ def perror(self, msg: Any = '', *, end: str = '\n', apply_style: bool = True) -> None:
"""Print message to sys.stderr
:param msg: message to print (anything convertible to a str with '{}'.format() is OK)
@@ -491,8 +491,8 @@ class Cmd(cmd.Cmd):
final_msg = "{}".format(msg)
ansi.ansi_aware_write(sys.stderr, final_msg + end)
- def pwarning(self, msg: Any, *, end: str = '\n', apply_style: bool = True) -> None:
- """Like perror, but applies ansi.style_warning by default
+ def pwarning(self, msg: Any = '', *, end: str = '\n', apply_style: bool = True) -> None:
+ """Wraps perror, but applies ansi.style_warning by default
:param msg: message to print (anything convertible to a str with '{}'.format() is OK)
:param end: string appended after the end of the message, default a newline
@@ -1424,7 +1424,7 @@ class Cmd(cmd.Cmd):
except Exception as e:
# Insert a newline so the exception doesn't print in the middle of the command line being tab completed
- self.perror('\n', end='')
+ self.perror()
self.pexcept(e)
return None
@@ -2741,7 +2741,8 @@ class Cmd(cmd.Cmd):
command = ''
self.stdout.write("\n")
- @with_argparser(DEFAULT_ARGUMENT_PARSER(description="List available shortcuts"))
+ shortcuts_parser = DEFAULT_ARGUMENT_PARSER(description="List available shortcuts")
+ @with_argparser(shortcuts_parser)
def do_shortcuts(self, _: argparse.Namespace) -> None:
"""List available shortcuts"""
# Sort the shortcut tuples by name
@@ -2749,13 +2750,15 @@ class Cmd(cmd.Cmd):
result = "\n".join('{}: {}'.format(sc[0], sc[1]) for sc in sorted_shortcuts)
self.poutput("Shortcuts for other commands:\n{}".format(result))
- @with_argparser(DEFAULT_ARGUMENT_PARSER(epilog=INTERNAL_COMMAND_EPILOG))
+ eof_parser = DEFAULT_ARGUMENT_PARSER(description="Called when <Ctrl>-D is pressed", epilog=INTERNAL_COMMAND_EPILOG)
+ @with_argparser(eof_parser)
def do_eof(self, _: argparse.Namespace) -> bool:
"""Called when <Ctrl>-D is pressed"""
# Return True to stop the command loop
return True
- @with_argparser(DEFAULT_ARGUMENT_PARSER(description="Exit this application"))
+ quit_parser = DEFAULT_ARGUMENT_PARSER(description="Exit this application")
+ @with_argparser(quit_parser)
def do_quit(self, _: argparse.Namespace) -> bool:
"""Exit this application"""
# Return True to stop the command loop
@@ -2794,7 +2797,7 @@ class Cmd(cmd.Cmd):
response = self.read_input(prompt)
except EOFError:
response = ''
- self.poutput('\n', end='')
+ self.poutput()
except KeyboardInterrupt as ex:
self.poutput('^C')
raise ex
@@ -3235,7 +3238,8 @@ class Cmd(cmd.Cmd):
# Only include the do_ipy() method if IPython is available on the system
if ipython_available: # pragma: no cover
- @with_argparser(DEFAULT_ARGUMENT_PARSER(description="Enter an interactive IPython shell"))
+ ipython_parser = DEFAULT_ARGUMENT_PARSER(description="Enter an interactive IPython shell")
+ @with_argparser(ipython_parser)
def do_ipy(self, _: argparse.Namespace) -> None:
"""Enter an interactive IPython shell"""
from .py_bridge import PyBridge