Skip to content

Commit 21dab8b

Browse files
authored
Merge pull request #901 from python-cmd2/api_docs_cleanup
Address comments from PR #899
2 parents f636aa1 + f18390b commit 21dab8b

File tree

12 files changed

+163
-57
lines changed

12 files changed

+163
-57
lines changed

cmd2/ansi.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@
1818
# Values for allow_style setting
1919
STYLE_NEVER = 'Never'
2020
"""
21-
Constant for ``cmd2.ansi.allow_style`` to indicate ANSI sequences
22-
should be removed from all output.
21+
Constant for ``cmd2.ansi.allow_style`` to indicate ANSI style sequences should
22+
be removed from all output.
2323
"""
2424
STYLE_TERMINAL = 'Terminal'
2525
"""
26-
Constant for ``cmd2.ansi.allow_style`` to indicate ANSI sequences
26+
Constant for ``cmd2.ansi.allow_style`` to indicate ANSI style sequences
2727
should be removed if the output is not going to the terminal.
2828
"""
2929
STYLE_ALWAYS = 'Always'
3030
"""
31-
Constant for ``cmd2.ansi.allow_style`` to indicate ANSI sequences
32-
should alwyas be output.
31+
Constant for ``cmd2.ansi.allow_style`` to indicate ANSI style sequences should
32+
always be output.
3333
"""
3434

35-
# Controls when ANSI style style sequences are allowed in output
35+
# Controls when ANSI style sequences are allowed in output
3636
allow_style = STYLE_TERMINAL
3737
"""When using outside of a cmd2 app, set this variable to one of:
3838
39-
- ``STYLE_NEVER`` - remove ANSI sequences from all output
40-
- ``STYLE_TERMINAL`` - remove ANSI sequences if the output is not going to the terminal
41-
- ``STYLE_ALWAYS`` - always output ANSI sequences
39+
- ``STYLE_NEVER`` - remove ANSI style sequences from all output
40+
- ``STYLE_TERMINAL`` - remove ANSI style sequences if the output is not going to the terminal
41+
- ``STYLE_ALWAYS`` - always output ANSI style sequences
4242
43-
to control the output of ANSI sequences by methods in this module.
43+
to control the output of ANSI style sequences by methods in this module.
4444
4545
The default is ``STYLE_TERMINAL``.
4646
"""

cmd2/argparse_custom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def my_completer_function(text, line, begidx, endidx):
9292
9393
Example::
9494
95-
# this adds file-path completion to an argument
95+
# This adds file-path completion to an argument
9696
parser.add_argument('-o', '--options', completer_method=cmd2.Cmd.path_complete)
9797
9898
@@ -101,7 +101,7 @@ def my_completer_function(text, line, begidx, endidx):
101101
102102
Example::
103103
104-
# this says to call path_complete with a preset value for its path_filter argument.
104+
# This says to call path_complete with a preset value for its path_filter argument
105105
completer_method = functools.partial(path_complete,
106106
path_filter=lambda path: os.path.isdir(path))
107107
parser.add_argument('-o', '--options', choices_method=completer_method)

cmd2/cmd2.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def remove_settable(self, name: str) -> None:
406406
raise KeyError(name + " is not a settable parameter")
407407

408408
def _build_settables(self):
409-
"""Construct the default settings"""
409+
"""Add default settables"""
410410
self.add_settable(Settable('allow_style', str,
411411
'Allow ANSI text style sequences in output (valid values: '
412412
'{}, {}, {})'.format(ansi.STYLE_TERMINAL,
@@ -2014,7 +2014,14 @@ def _restore_output(self, statement: Statement, saved_state: utils.RedirectionSa
20142014
def cmd_func(self, command: str) -> Optional[Callable]:
20152015
"""
20162016
Get the function for a command
2017+
20172018
:param command: the name of the command
2019+
2020+
:Example:
2021+
2022+
>>> helpfunc = self.cmd_func('help')
2023+
2024+
helpfunc now contains a reference to the ``do_help`` method
20182025
"""
20192026
func_name = self._cmd_func_name(command)
20202027
if func_name:

cmd2/decorators.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
"""Decorators for cmd2 commands"""
2+
"""Decorators for ``cmd2`` commands"""
33
import argparse
44
from typing import Callable, List, Optional, Union
55

@@ -44,9 +44,9 @@ def with_argument_list(*args: List[Callable], preserve_quotes: bool = False) ->
4444
:Example:
4545
4646
>>> class MyApp(cmd2.Cmd):
47-
>>> @cmd2.with_argument_list
48-
>>> def do_echo(self, arglist):
49-
>>> self.poutput(' '.join(arglist)
47+
>>> @cmd2.with_argument_list
48+
>>> def do_echo(self, arglist):
49+
>>> self.poutput(' '.join(arglist)
5050
"""
5151
import functools
5252

@@ -112,6 +112,20 @@ def with_argparser_and_unknown_args(parser: argparse.ArgumentParser, *,
112112
of unknown argument strings. A member called ``__statement__`` is added to the
113113
``Namespace`` to provide command functions access to the :class:`cmd2.Statement`
114114
object. This can be useful if the command function needs to know the command line.
115+
116+
:Example:
117+
118+
>>> parser = argparse.ArgumentParser()
119+
>>> parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
120+
>>> parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
121+
>>> parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
122+
>>>
123+
>>> class MyApp(cmd2.Cmd):
124+
>>> @cmd2.with_argparser_and_unknown_args(parser)
125+
>>> def do_argprint(self, args, unknown):
126+
>>> "Print the options and argument list this options command was called with."
127+
>>> self.poutput('args: {!r}'.format(args))
128+
>>> self.poutput('unknowns: {}'.format(unknown))
115129
"""
116130
import functools
117131

@@ -170,6 +184,20 @@ def with_argparser(parser: argparse.ArgumentParser, *,
170184
:return: function that gets passed the argparse-parsed args in a Namespace
171185
A member called __statement__ is added to the Namespace to provide command functions access to the
172186
Statement object. This can be useful if the command function needs to know the command line.
187+
188+
:Example:
189+
190+
>>> parser = argparse.ArgumentParser()
191+
>>> parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
192+
>>> parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
193+
>>> parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
194+
>>> parser.add_argument('words', nargs='+', help='words to print')
195+
>>>
196+
>>> class MyApp(cmd2.Cmd):
197+
>>> @cmd2.with_argparser(parser, preserve_quotes=True)
198+
>>> def do_argprint(self, args):
199+
>>> "Print the options and argument list this options command was called with."
200+
>>> self.poutput('args: {!r}'.format(args))
173201
"""
174202
import functools
175203

docs/api/cmd.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ cmd2.Cmd
5252
A record of previously entered commands.
5353

5454
This attribute is an instance of :class:`cmd2.history.History`, and
55-
each command is an instance of :class:`cmd2.history.HistoryItem`.
55+
each command is an instance of :class:`cmd2.Statement`.
5656

5757
.. attribute:: statement_parser
5858

docs/api/history.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
cmd2.history
22
===============
33

4+
Classes for storing the history of previously entered commands.
5+
6+
47
.. autoclass:: cmd2.history.History
58
:members:
69

docs/api/index.rst

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,42 @@ If a release of this library changes any of the items documented here, the
1212
version number will be incremented according to the `Semantic Version
1313
Specification <https://semver.org>`_.
1414

15-
This documentation is for version |version| of ``cmd2``.
15+
This documentation is for ``cmd2`` version |version|.
1616

1717
.. toctree::
1818
:maxdepth: 1
19+
:hidden:
1920

2021
cmd
21-
parsing
2222
decorators
23-
history
23+
parsing
2424
argparse_completer
2525
argparse_custom
2626
ansi
2727
utils
28+
history
2829
plugin
2930
py_bridge
3031
constants
32+
33+
**Modules**
34+
35+
- :ref:`api/cmd:cmd2.Cmd` - functions and attributes of the main
36+
class in this library
37+
- :ref:`api/decorators:cmd2.decorators` - decorators for ``cmd2``
38+
commands
39+
- :ref:`api/parsing:cmd2.parsing` - classes for parsing and storing
40+
user input
41+
- :ref:`api/argparse_completer:cmd2.argparse_completer` - classes for
42+
``argparse``-based tab completion
43+
- :ref:`api/argparse_custom:cmd2.argparse_custom` - classes and functions
44+
for extending ``argparse``
45+
- :ref:`api/ansi:cmd2.ansi` - convenience classes and functions for generating
46+
ANSI escape sequences to style text in the terminal
47+
- :ref:`api/utils:cmd2.utils` - various utility classes and functions
48+
- :ref:`api/history:cmd2.history` - classes for storing the history
49+
of previously entered commands
50+
- :ref:`api/plugin:cmd2.plugin` - data classes for hook methods
51+
- :ref:`api/py_bridge:cmd2.py_bridge` - classes for bridging calls from the
52+
embedded python environment to the host app
53+
- :ref:`api/constants:cmd2.constants` - just like it says on the tin

docs/api/parsing.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
cmd2.parsing
22
===============
33

4+
Classes for parsing and storing user input.
5+
6+
7+
.. autoclass:: cmd2.parsing.StatementParser
8+
:members:
9+
10+
.. automethod:: __init__
11+
12+
413
.. autoclass:: cmd2.Statement
514
:members:
615

@@ -67,9 +76,3 @@ cmd2.parsing
6776

6877
If output was redirected by the user, this contains the requested destination with
6978
quotes preserved.
70-
71-
72-
.. autoclass:: cmd2.parsing.StatementParser
73-
:members:
74-
75-
.. automethod:: __init__

docs/api/utils.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ Tab Completion
4242
.. autoclass:: cmd2.utils.CompletionError
4343
:members:
4444

45-
.. autofunction:: cmd2.utils.remove_duplicates
46-
47-
.. autofunction:: cmd2.utils.alphabetical_sort
48-
49-
.. autofunction:: cmd2.utils.natural_sort
50-
5145
.. autofunction:: cmd2.utils.basic_complete
5246

5347

@@ -76,3 +70,9 @@ Miscellaneous
7670
.. autofunction:: cmd2.utils.namedtuple_with_defaults
7771

7872
.. autofunction:: cmd2.utils.categorize
73+
74+
.. autofunction:: cmd2.utils.remove_duplicates
75+
76+
.. autofunction:: cmd2.utils.alphabetical_sort
77+
78+
.. autofunction:: cmd2.utils.natural_sort

docs/doc_conventions.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ comment instead of just #), or in a docstring after the definition. This
159159
project has standardized on the docstring after the definition approach. Do not
160160
use the specially formatted comment approach.
161161

162+
When using the Sphix ``autoclass`` directive, it must be preceded by two blank
163+
lines like so:
164+
165+
.. code-block:: rst
166+
167+
Classes for storing the history of previously entered commands.
168+
169+
170+
.. autoclass:: cmd2.history.History
171+
:members:
172+
173+
174+
.. autoclass:: cmd2.history.HistoryItem
175+
:members:
176+
162177
163178
Links to API Reference
164179
----------------------

0 commit comments

Comments
 (0)