summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-23 20:49:27 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-23 20:49:27 -0400
commit652122f3c9907a652a9c3a14581bb2aef90bc996 (patch)
tree9bcb0c07c2e2cee26553a1e11a1d9dbcb7225954 /cmd2
parent181cecb217dd73056b72874d225e34528d484de8 (diff)
downloadcmd2-git-652122f3c9907a652a9c3a14581bb2aef90bc996.tar.gz
Made last_result public and restored the initialization of it in __init__ and associated comment
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/cmd2.py4
-rw-r--r--cmd2/pyscript_bridge.py6
2 files changed, 7 insertions, 3 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 6a518978..d44e6df4 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -423,6 +423,10 @@ class Cmd(cmd.Cmd):
# True if running inside a Python script or interactive console, False otherwise
self._in_py = False
+ # Stores results from the last command run to enable usage of results in a Python script or interactive console
+ # Built-in commands don't make use of this. It is purely there for user-defined commands and convenience.
+ self.last_result = None
+
# Used by run_script command to store current script dir as a LIFO queue to support _relative_run_script command
self._script_dir = []
diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py
index 01d283ea..ac3dfd40 100644
--- a/cmd2/pyscript_bridge.py
+++ b/cmd2/pyscript_bridge.py
@@ -23,7 +23,7 @@ class CommandResult(namedtuple_with_defaults('CommandResult', ['stdout', 'stderr
Any combination of these fields can be used when developing a scripting API for a given command.
By default stdout, stderr, and stop will be captured for you. If there is additional command specific data,
- then write that to cmd2's _last_result member. That becomes the data member of this tuple.
+ then write that to cmd2's last_result member. That becomes the data member of this tuple.
In some cases, the data member may contain everything needed for a command and storing stdout
and stderr might just be a duplication of data that wastes memory. In that case, the StdSim can
@@ -88,7 +88,7 @@ class PyscriptBridge(object):
# This will be used to capture sys.stderr
copy_stderr = StdSim(sys.stderr, echo)
- self._cmd2_app._last_result = None
+ self._cmd2_app.last_result = None
stop = False
try:
@@ -105,5 +105,5 @@ class PyscriptBridge(object):
result = CommandResult(stdout=copy_cmd_stdout.getvalue(),
stderr=copy_stderr.getvalue() if copy_stderr.getvalue() else None,
stop=stop,
- data=self._cmd2_app._last_result)
+ data=self._cmd2_app.last_result)
return result