diff options
author | kmvanbrunt <kmvanbrunt@gmail.com> | 2018-10-05 16:37:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-05 16:37:21 -0400 |
commit | ad5614ee19d5290d80b50593253667e018aee311 (patch) | |
tree | 86dd3142e0ccd7ef7a3c451237d5cd820c2bfe21 /cmd2/pyscript_bridge.py | |
parent | 9fee6105210b36201b5d2edc610f20bd67eac9f2 (diff) | |
parent | afd10b31e8c3064301e008299aeaff6d5b2fdcdf (diff) | |
download | cmd2-git-ad5614ee19d5290d80b50593253667e018aee311.tar.gz |
Merge pull request #569 from python-cmd2/command_result
No longer using stderr and self.data together to determine truthiness of a CommandResult.
Diffstat (limited to 'cmd2/pyscript_bridge.py')
-rw-r--r-- | cmd2/pyscript_bridge.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py index 2002ca6d..7c09aab0 100644 --- a/cmd2/pyscript_bridge.py +++ b/cmd2/pyscript_bridge.py @@ -33,9 +33,16 @@ class CommandResult(namedtuple_with_defaults('CommandResult', ['stdout', 'stderr NOTE: Named tuples are immutable. So the contents are there for access, not for modification. """ - def __bool__(self): - """If stderr is None and data is not None the command is considered a success""" - return not self.stderr and self.data is not None + def __bool__(self) -> bool: + """Returns True if the command succeeded, otherwise False""" + + # If data has a __bool__ method, then call it to determine success of command + if self.data is not None and callable(getattr(self.data, '__bool__', None)): + return bool(self.data) + + # Otherwise check if stderr was filled out + else: + return not self.stderr def _exec_cmd(cmd2_app, func: Callable, echo: bool) -> CommandResult: |