MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / run_cmd

Function run_cmd

tests/conftest.py:62–80  ·  view source on GitHub ↗

Run the command in app and return what it writes to app.stdout and sys.stderr.

(app: cmd2.Cmd, cmd: str)

Source from the content-addressed store, hash-verified

60
61
62def run_cmd(app: cmd2.Cmd, cmd: str) -> tuple[list[str], list[str]]:
63 """Run the command in app and return what it writes to app.stdout and sys.stderr."""
64
65 # This will be used to capture app.stdout
66 copy_cmd_stdout = StdSim(cast(TextIO, app.stdout))
67
68 # This will be used to capture sys.stderr
69 copy_stderr = StdSim(sys.stderr)
70
71 try:
72 app.stdout = cast(TextIO, copy_cmd_stdout)
73 with redirect_stderr(cast(TextIO, copy_stderr)):
74 app.onecmd_plus_hooks(cmd)
75 finally:
76 app.stdout = cast(TextIO, copy_cmd_stdout.inner_stream)
77
78 out = copy_cmd_stdout.getvalue()
79 err = copy_stderr.getvalue()
80 return normalize(out), normalize(err)
81
82
83@pytest.fixture

Calls 4

getvalueMethod · 0.95
StdSimClass · 0.90
normalizeFunction · 0.85
onecmd_plus_hooksMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…