Skip to content

Commit 990ec45

Browse files
authored
Merge pull request #908 from python-cmd2/shell_pyscript
do_shell integration with pyscript
2 parents 36864f4 + c3e424e commit 990ec45

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.2 (TBD, 2020)
2+
* Enhancements
3+
* `do_shell()` now saves the return code of the command it runs in `self.last_result` for use in pyscripts
4+
15
## 1.0.1 (March 13, 2020)
26
* Bug Fixes
37
* Fixed issue where postcmd hooks were running after an `argparse` exception in a command.

cmd2/cmd2.py

+3
Original file line numberDiff line numberDiff line change
@@ -3015,6 +3015,9 @@ def do_shell(self, args: argparse.Namespace) -> None:
30153015
proc_reader = utils.ProcReader(proc, self.stdout, sys.stderr)
30163016
proc_reader.wait()
30173017

3018+
# Save the return code of the application for use in a pyscript
3019+
self.last_result = proc.returncode
3020+
30183021
@staticmethod
30193022
def _reset_py_display() -> None:
30203023
"""

tests/test_cmd2.py

+4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ def test_base_shell(base_app, monkeypatch):
203203
assert out == []
204204
assert m.called
205205

206+
def test_shell_last_result(base_app):
207+
base_app.last_result = None
208+
run_cmd(base_app, 'shell fake')
209+
assert base_app.last_result is not None
206210

207211
def test_base_py(base_app):
208212
# Make sure py can't edit Cmd.py_locals. It used to be that cmd2 was passing its py_locals

0 commit comments

Comments
 (0)