summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2018-05-02 11:22:10 -0400
committerEric Lin <anselor@gmail.com>2018-05-02 11:22:10 -0400
commit2528fb5217063a5a98f7ea2b880bfc75e7f2428c (patch)
treebfa1d30d5a2e1cebeffac4ea8d867588105b79a9 /cmd2/cmd2.py
parentbf5288829afde976dd213d15aa37704c3eb0a087 (diff)
downloadcmd2-git-2528fb5217063a5a98f7ea2b880bfc75e7f2428c.tar.gz
Added support for customizing the pyscript bridge pystate object name.
Removed all legacy pystate objects. Changed default behavior to clear _last_result before each command Added utility for creating named tuples with default values Added tests to exercise new changes.
Diffstat (limited to 'cmd2/cmd2.py')
-rwxr-xr-xcmd2/cmd2.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index dc55d4c5..3a07f8ce 100755
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -761,6 +761,7 @@ class Cmd(cmd.Cmd):
self.initial_stdout = sys.stdout
self.history = History()
self.pystate = {}
+ self.pyscript_name = 'app'
self.keywords = self.reserved_words + [fname[3:] for fname in dir(self) if fname.startswith('do_')]
self.parser_manager = ParserManager(redirector=self.redirector, terminators=self.terminators,
multilineCommands=self.multilineCommands,
@@ -2075,6 +2076,8 @@ class Cmd(cmd.Cmd):
if self.allow_redirection:
self._redirect_output(statement)
timestart = datetime.datetime.now()
+ if self._in_py:
+ self._last_result = None
statement = self.precmd(statement)
stop = self.onecmd(statement)
stop = self.postcmd(stop, statement)
@@ -2901,10 +2904,8 @@ Usage: Usage: unalias [-a] name [name ...]
return self.onecmd_plus_hooks(cmd_plus_args + '\n')
bridge = PyscriptBridge(self)
- self.pystate['self'] = bridge
self.pystate['run'] = run
- self.pystate['cmd'] = bridge
- self.pystate['app'] = bridge
+ self.pystate[self.pyscript_name] = bridge
localvars = (self.locals_in_py and self.pystate) or {}
interp = InteractiveConsole(locals=localvars)