MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / CommandResult

Class CommandResult

cmd2/py_bridge.py:23–71  ·  view source on GitHub ↗

Encapsulates the results from a cmd2 app command. :stdout: str - output captured from stdout while this command is executing :stderr: str - output captured from stderr while this command is executing :stop: bool - return value of onecmd_plus_hooks after it runs the given comm

Source from the content-addressed store, hash-verified

21
22
23class CommandResult(NamedTuple):
24 """Encapsulates the results from a cmd2 app command.
25
26 :stdout: str - output captured from stdout while this command is executing
27 :stderr: str - output captured from stderr while this command is executing
28 :stop: bool - return value of onecmd_plus_hooks after it runs the given
29 command line.
30 :data: possible data populated by the command.
31
32 Any combination of these fields can be used when developing a scripting API
33 for a given command. By default stdout, stderr, and stop will be captured
34 for you. If there is additional command specific data, then write that to
35 cmd2's last_result member. That becomes the data member of this tuple.
36
37 In some cases, the data member may contain everything needed for a command
38 and storing stdout and stderr might just be a duplication of data that
39 wastes memory. In that case, the StdSim can be told not to store output
40 with its pause_storage member. While this member is True, any output sent
41 to StdSim won't be saved in its buffer.
42
43 The code would look like this::
44
45 if isinstance(self.stdout, StdSim):
46 self.stdout.pause_storage = True
47
48 if isinstance(sys.stderr, StdSim):
49 sys.stderr.pause_storage = True
50
51 See [cmd2.utils.StdSim][] for more information.
52
53 .. note::
54
55 Named tuples are immutable. The contents are there for access,
56 not for modification.
57 """
58
59 stdout: str = ""
60 stderr: str = ""
61 stop: bool = False
62 data: Any = None
63
64 def __bool__(self) -> bool:
65 """Return True if the command succeeded, otherwise False."""
66 # If data was set, then use it to determine success
67 if self.data is not None:
68 return bool(self.data)
69
70 # Otherwise check if stderr was filled out
71 return not self.stderr
72
73
74class PyBridge:

Callers 1

__call__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…