summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-02-22 16:16:16 -0500
committerGitHub <noreply@github.com>2017-02-22 16:16:16 -0500
commit2154d8fb69820a0035ae1fe4d5abd981f0637e86 (patch)
tree68d0dea3cc7e69701bad2eeb767b60b1d5e80b8b /cmd2.py
parent7fe7cf1528d70d270cac3cc1347e21bf8d67e447 (diff)
parent68216892804f64dd8bb4936191792de975725b49 (diff)
downloadcmd2-git-2154d8fb69820a0035ae1fe4d5abd981f0637e86.tar.gz
Merge pull request #53 from python-cmd2/empty_statement
Changed EmptyStatement behavior so postparsing_postcmd() always runs.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/cmd2.py b/cmd2.py
index c8d3c7b9..05ec46d6 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -151,9 +151,9 @@ class OptionParser(optparse.OptionParser):
def remaining_args(opts_plus_args, arg_list):
""" Preserves the spacing originally in the arguments after the removal of options.
-
+
:param opts_plus_args: str - original argument string, including options
- :param arg_list: List[str] - list of strings containing the non-option arguments
+ :param arg_list: List[str] - list of strings containing the non-option arguments
:return: str - non-option arguments as a single string, with original spacing preserved
"""
pattern = '\s+'.join(re.escape(a) for a in arg_list) + '\s*$'
@@ -413,7 +413,7 @@ class ParsedString(str):
class StubbornDict(dict):
""" Dictionary that tolerates many input formats.
-
+
Create it with the stubbornDict(arg) factory function.
"""
def update(self, arg):
@@ -459,7 +459,7 @@ class StubbornDict(dict):
def stubbornDict(*arg, **kwarg):
""" Factory function which creates instances of the StubornDict class.
-
+
:param arg: an argument which could be used to construct a built-in dict dictionary
:param kwarg: a variable number of key/value pairs
:return: StubbornDict - a StubbornDict containing everything in both arg and kwarg
@@ -495,7 +495,7 @@ class Cmd(cmd.Cmd):
Extends the Python Standard Library’s cmd package by adding a lot of useful features
to the out of the box configuration.
-
+
Line-oriented command interpreters are often useful for test harnesses, internal tools, and rapid prototypes.
"""
# TODO: Move all instance member initializations inside __init__()
@@ -577,7 +577,7 @@ class Cmd(cmd.Cmd):
def __init__(self, completekey='tab', stdin=None, stdout=None, use_ipython=False):
"""An easy but powerful framework for writing line-oriented command interpreters, extends Python's cmd package.
-
+
:param completekey: str - (optional) readline name of a completion key, default to Tab
:param stdin: (optional) alternate input file object, if not specified, sys.stdin is used
:param stdout: (optional) alternate output file object, if not specified, sys.stdout is used
@@ -797,6 +797,9 @@ class Cmd(cmd.Cmd):
def postparsing_postcmd(self, stop):
"""This runs after everything else, including after postcmd().
+ It even runs when an empty line is entered. Thus, if you need to do something like update the prompt due
+ to notifications from a background thread, then this is the method you want to override to do it.
+
:param stop: bool - True implies the entire application should exit.
:return: bool - True implies the entire application should exit.
"""
@@ -845,7 +848,7 @@ class Cmd(cmd.Cmd):
if self.allow_redirection:
self.restore_output(statement)
except EmptyStatement:
- return 0
+ pass
except ValueError as ex:
# If shlex.split failed on syntax, let user know whats going on
self.perror("Invalid syntax: {}".format(ex), traceback_war=False)
@@ -1186,7 +1189,7 @@ class Cmd(cmd.Cmd):
if ipython_available:
def do_ipy(self, arg):
"""Enters an interactive IPython shell.
-
+
Run python code from external files with ``run filename.py``
End with ``Ctrl-D`` (Unix) / ``Ctrl-Z`` (Windows), ``quit()``, '`exit()``.
"""