Skip to content

Commit acf269f

Browse files
committed
Add py_bridge API documentation
1 parent 44bf30a commit acf269f

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

cmd2/py_bridge.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding=utf-8
22
"""
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.
55
"""
66

77
import sys
@@ -14,32 +14,38 @@
1414
class CommandResult(namedtuple_with_defaults('CommandResult', ['stdout', 'stderr', 'stop', 'data'])):
1515
"""Encapsulates the results from a cmd2 app command
1616
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.
2323
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.
2728
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::
3236
33-
The code would look like this:
3437
if isinstance(self.stdout, StdSim):
3538
self.stdout.pause_storage = True
3639
3740
if isinstance(sys.stderr, StdSim):
3841
sys.stderr.pause_storage = True
3942
40-
See StdSim class in utils.py for more information
43+
See :class:`~cmd2.utils.StdSim` for more information.
44+
45+
.. note::
4146
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.
4349
"""
4450
def __bool__(self) -> bool:
4551
"""Returns True if the command succeeded, otherwise False"""

docs/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ API Reference
1313
ansi
1414
utils
1515
plugin
16+
py_bridge
1617
constants

docs/api/py_bridge.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cmd2.py_bridge
2+
==============
3+
4+
.. automodule:: cmd2.py_bridge
5+
:members:

0 commit comments

Comments
 (0)