diff options
Diffstat (limited to 'cmd2/py_bridge.py')
-rw-r--r-- | cmd2/py_bridge.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/cmd2/py_bridge.py b/cmd2/py_bridge.py index a9b8641d..6f2160c6 100644 --- a/cmd2/py_bridge.py +++ b/cmd2/py_bridge.py @@ -9,9 +9,7 @@ from contextlib import ( redirect_stderr, redirect_stdout, ) -from typing import ( - Optional, -) +from typing import Optional from .utils import ( StdSim, @@ -55,6 +53,7 @@ class CommandResult(namedtuple_with_defaults('CommandResult', ['stdout', 'stderr Named tuples are immutable. The contents are there for access, not for modification. """ + def __bool__(self) -> bool: """Returns True if the command succeeded, otherwise False""" @@ -69,6 +68,7 @@ class CommandResult(namedtuple_with_defaults('CommandResult', ['stdout', 'stderr class PyBridge: """Provides a Python API wrapper for application commands.""" + def __init__(self, cmd2_app): self._cmd2_app = cmd2_app self.cmd_echo = False @@ -117,8 +117,10 @@ class PyBridge: self.stop = stop or self.stop # Save the output. If stderr is empty, set it to None. - 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) + 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, + ) return result |