summaryrefslogtreecommitdiff
path: root/cmd2/pyscript_bridge.py
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2018-10-06 18:15:23 +0000
committerEric Lin <anselor@gmail.com>2018-10-06 18:15:23 +0000
commitfb575e41251156a90044055e8a352079e4f75866 (patch)
treec8f013e04d7a9e28164367228fb0249e5b1dbbb2 /cmd2/pyscript_bridge.py
parent6d79731ae51229d46263dcddfc945946afa6e238 (diff)
parent467be57e647112f536becc8625ffa080cb67a0ce (diff)
downloadcmd2-git-fb575e41251156a90044055e8a352079e4f75866.tar.gz
Merge remote-tracking branch 'origin/master' into argparse_remainder
Diffstat (limited to 'cmd2/pyscript_bridge.py')
-rw-r--r--cmd2/pyscript_bridge.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py
index 7920e1be..8187d7fd 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:
@@ -91,7 +98,7 @@ class ArgparseFunctor:
return commands
def __getattr__(self, item: str):
- """Search for a subcommand matching this item and update internal state to track the traversal"""
+ """Search for a sub-command matching this item and update internal state to track the traversal"""
# look for sub-command under the current command/sub-command layer
for action in self.__current_subcommand_parser._actions:
if not action.option_strings and isinstance(action, argparse._SubParsersAction):