diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-07 16:15:12 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-07 16:15:12 -0400 |
commit | ab1ae68d2747b82812b03edbbccfbca39cf1c638 (patch) | |
tree | 812e74a9b465da44f15eee0e211d0baf7f4b209b /cmd2/cmd2.py | |
parent | ee699c35159a621e59bf8205c555d0fbf8aa3734 (diff) | |
download | cmd2-git-ab1ae68d2747b82812b03edbbccfbca39cf1c638.tar.gz |
Removed self._should_quit from cmd2 and add logic to PyscriptBridge to return whether a command returned True for stop.
Added stop to CommandResult so pyscripts can now know the return value of a command's do_* function.
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 65574095..29f34175 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -425,9 +425,6 @@ class Cmd(cmd.Cmd): shortcuts=shortcuts) self._transcript_files = transcript_files - # Used to enable the ability for a Python script to quit the application - self._should_quit = False - # True if running inside a Python script or interactive console, False otherwise self._in_py = False @@ -2836,7 +2833,6 @@ class Cmd(cmd.Cmd): @with_argparser(ACArgumentParser()) def do_quit(self, _: argparse.Namespace) -> bool: """Exit this application""" - self._should_quit = True # Return True to stop the command loop return True @@ -3053,6 +3049,8 @@ class Cmd(cmd.Cmd): self.perror(err, traceback_war=False) return False + bridge = PyscriptBridge(self) + try: self._in_py = True @@ -3078,7 +3076,6 @@ class Cmd(cmd.Cmd): raise EmbeddedConsoleExit # Set up Python environment - bridge = PyscriptBridge(self) self.pystate[self.pyscript_name] = bridge self.pystate['run'] = py_run self.pystate['quit'] = py_quit @@ -3223,7 +3220,7 @@ class Cmd(cmd.Cmd): finally: self._in_py = False - return self._should_quit + return bridge.stop pyscript_parser = ACArgumentParser() setattr(pyscript_parser.add_argument('script_path', help='path to the script file'), |