|
1 | 1 | # coding=utf-8 |
2 | 2 | """ |
3 | | -Bridges calls made inside of a Python environment to the Cmd2 host app while maintaining a reasonable |
4 | | -degree of isolation between the two |
| 3 | +Bridges calls made inside of a Python environment to the Cmd2 host app |
| 4 | +while maintaining a reasonable degree of isolation between the two. |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import sys |
|
14 | 14 | class CommandResult(namedtuple_with_defaults('CommandResult', ['stdout', 'stderr', 'stop', 'data'])): |
15 | 15 | """Encapsulates the results from a cmd2 app command |
16 | 16 |
|
17 | | - Named tuple attributes |
18 | | - ---------------------- |
19 | | - stdout: str - output captured from stdout while this command is executing |
20 | | - stderr: str - output captured from stderr while this command is executing. None if no error captured. |
21 | | - stop: bool - return value of onecmd_plus_hooks after it runs the given command line. |
22 | | - data - possible data populated by the command. |
| 17 | + :stdout: str - output captured from stdout while this command is executing |
| 18 | + :stderr: str - output captured from stderr while this command is executing |
| 19 | + None if no error captured. |
| 20 | + :stop: bool - return value of onecmd_plus_hooks after it runs the given |
| 21 | + command line. |
| 22 | + :data: possible data populated by the command. |
23 | 23 |
|
24 | | - Any combination of these fields can be used when developing a scripting API for a given command. |
25 | | - By default stdout, stderr, and stop will be captured for you. If there is additional command specific data, |
26 | | - then write that to cmd2's last_result member. That becomes the data member of this tuple. |
| 24 | + Any combination of these fields can be used when developing a scripting API |
| 25 | + for a given command. By default stdout, stderr, and stop will be captured |
| 26 | + for you. If there is additional command specific data, then write that to |
| 27 | + cmd2's last_result member. That becomes the data member of this tuple. |
27 | 28 |
|
28 | | - In some cases, the data member may contain everything needed for a command and storing stdout |
29 | | - and stderr might just be a duplication of data that wastes memory. In that case, the StdSim can |
30 | | - be told not to store output with its pause_storage member. While this member is True, any output |
31 | | - sent to StdSim won't be saved in its buffer. |
| 29 | + In some cases, the data member may contain everything needed for a command |
| 30 | + and storing stdout and stderr might just be a duplication of data that |
| 31 | + wastes memory. In that case, the StdSim can be told not to store output |
| 32 | + with its pause_storage member. While this member is True, any output sent |
| 33 | + to StdSim won't be saved in its buffer. |
| 34 | +
|
| 35 | + The code would look like this:: |
32 | 36 |
|
33 | | - The code would look like this: |
34 | 37 | if isinstance(self.stdout, StdSim): |
35 | 38 | self.stdout.pause_storage = True |
36 | 39 |
|
37 | 40 | if isinstance(sys.stderr, StdSim): |
38 | 41 | sys.stderr.pause_storage = True |
39 | 42 |
|
40 | | - See StdSim class in utils.py for more information |
| 43 | + See :class:`~cmd2.utils.StdSim` for more information. |
| 44 | +
|
| 45 | + .. note:: |
41 | 46 |
|
42 | | - NOTE: Named tuples are immutable. So the contents are there for access, not for modification. |
| 47 | + Named tuples are immutable. The contents are there for access, |
| 48 | + not for modification. |
43 | 49 | """ |
44 | 50 | def __bool__(self) -> bool: |
45 | 51 | """Returns True if the command succeeded, otherwise False""" |
|
0 commit comments