Skip to content

Commit e60bd2d

Browse files
committed
Added mkdocstrings cross-references
1 parent 152d117 commit e60bd2d

21 files changed

+163
-171
lines changed

cmd2/ansi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,13 +1043,13 @@ def style(
10431043
# These can be altered to suit an application's needs and only need to be a
10441044
# function with the following structure: func(str) -> str
10451045
style_success = functools.partial(style, fg=Fg.GREEN)
1046-
"""Partial function supplying arguments to :meth:`cmd2.ansi.style()` which colors text to signify success"""
1046+
"""Partial function supplying arguments to [cmd2.ansi.style][] which colors text to signify success"""
10471047

10481048
style_warning = functools.partial(style, fg=Fg.LIGHT_YELLOW)
1049-
"""Partial function supplying arguments to :meth:`cmd2.ansi.style()` which colors text to signify a warning"""
1049+
"""Partial function supplying arguments to [cmd2.ansi.style][] which colors text to signify a warning"""
10501050

10511051
style_error = functools.partial(style, fg=Fg.LIGHT_RED)
1052-
"""Partial function supplying arguments to :meth:`cmd2.ansi.style()` which colors text to signify an error"""
1052+
"""Partial function supplying arguments to [cmd2.ansi.style][] which colors text to signify an error"""
10531053

10541054

10551055
def async_alert_str(*, terminal_columns: int, prompt: str, line: str, cursor_offset: int, alert_msg: str) -> str:

cmd2/argparse_custom.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -198,40 +198,28 @@ def my_completer(self, text, line, begidx, endidx, arg_tokens)
198198
cmd2 has patched ``argparse.Action`` to include the following accessor methods
199199
for cases in which you need to manually access the cmd2-specific attributes.
200200
201-
- ``argparse.Action.get_choices_callable()`` - See
202-
:func:`_action_get_choices_callable` for more details.
203-
- ``argparse.Action.set_choices_provider()`` - See
204-
:func:`_action_set_choices_provider` for more details.
205-
- ``argparse.Action.set_completer()`` - See
206-
:func:`_action_set_completer` for more details.
207-
- ``argparse.Action.get_descriptive_header()`` - See
208-
:func:`_action_get_descriptive_header` for more details.
209-
- ``argparse.Action.set_descriptive_header()`` - See
210-
:func:`_action_set_descriptive_header` for more details.
211-
- ``argparse.Action.get_nargs_range()`` - See
212-
:func:`_action_get_nargs_range` for more details.
213-
- ``argparse.Action.set_nargs_range()`` - See
214-
:func:`_action_set_nargs_range` for more details.
215-
- ``argparse.Action.get_suppress_tab_hint()`` - See
216-
:func:`_action_get_suppress_tab_hint` for more details.
217-
- ``argparse.Action.set_suppress_tab_hint()`` - See
218-
:func:`_action_set_suppress_tab_hint` for more details.
201+
- ``argparse.Action.get_choices_callable()`` - See `action_get_choices_callable` for more details.
202+
- ``argparse.Action.set_choices_provider()`` - See `_action_set_choices_provider` for more details.
203+
- ``argparse.Action.set_completer()`` - See `_action_set_completer` for more details.
204+
- ``argparse.Action.get_descriptive_header()`` - See `_action_get_descriptive_header` for more details.
205+
- ``argparse.Action.set_descriptive_header()`` - See `_action_set_descriptive_header` for more details.
206+
- ``argparse.Action.get_nargs_range()`` - See `_action_get_nargs_range` for more details.
207+
- ``argparse.Action.set_nargs_range()`` - See `_action_set_nargs_range` for more details.
208+
- ``argparse.Action.get_suppress_tab_hint()`` - See `_action_get_suppress_tab_hint` for more details.
209+
- ``argparse.Action.set_suppress_tab_hint()`` - See `_action_set_suppress_tab_hint` for more details.
219210
220211
cmd2 has patched ``argparse.ArgumentParser`` to include the following accessor methods
221212
222-
- ``argparse.ArgumentParser.get_ap_completer_type()`` - See
223-
:func:`_ArgumentParser_get_ap_completer_type` for more details.
224-
- ``argparse.Action.set_ap_completer_type()`` - See
225-
:func:`_ArgumentParser_set_ap_completer_type` for more details.
213+
- ``argparse.ArgumentParser.get_ap_completer_type()`` - See `_ArgumentParser_get_ap_completer_type` for more details.
214+
- ``argparse.Action.set_ap_completer_type()`` - See `_ArgumentParser_set_ap_completer_type` for more details.
226215
227216
**Subcommand removal**
228217
229218
cmd2 has patched ``argparse._SubParsersAction`` to include a ``remove_parser()``
230219
method which can be used to remove a subcommand.
231220
232221
``argparse._SubParsersAction.remove_parser`` - new function which removes a
233-
sub-parser from a sub-parsers group. See
234-
:func:`_SubParsersAction_remove_parser` for more details.
222+
sub-parser from a sub-parsers group. See _SubParsersAction_remove_parser` for more details.
235223
"""
236224

237225
import argparse

cmd2/cmd2.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def __init__(
349349
suppressed. Anything written to stderr will still display.
350350
:param include_py: should the "py" command be included for an embedded Python shell
351351
:param include_ipy: should the "ipy" command be included for an embedded IPython shell
352-
:param allow_cli_args: if ``True``, then :meth:`cmd2.Cmd.__init__` will process command
352+
:param allow_cli_args: if ``True``, then [cmd2.Cmd.__init__][] will process command
353353
line arguments as either commands to be run or, if ``-t`` or
354354
``--test`` are given, transcript files to run. This should be
355355
set to ``False`` if your application parses its own command line
@@ -2446,50 +2446,47 @@ def _raise_keyboard_interrupt(self) -> None:
24462446

24472447
def precmd(self, statement: Union[Statement, str]) -> Statement:
24482448
"""Hook method executed just before the command is executed by
2449-
:meth:`~cmd2.Cmd.onecmd` and after adding it to history.
2449+
[cmd2.Cmd.onecmd][] and after adding it to history.
24502450
24512451
:param statement: subclass of str which also contains the parsed input
24522452
:return: a potentially modified version of the input Statement object
24532453
2454-
See :meth:`~cmd2.Cmd.register_postparsing_hook` and
2455-
:meth:`~cmd2.Cmd.register_precmd_hook` for more robust ways
2454+
See [cmd2.Cmd.register_postparsing_hook][] and
2455+
[cmd2.Cmd.register_precmd_hook][] for more robust ways
24562456
to run hooks before the command is executed. See
2457-
:ref:`features/hooks:Postparsing Hooks` and
2458-
:ref:`features/hooks:Precommand Hooks` for more information.
2457+
[Hooks](../features/hooks.md) for more information.
24592458
"""
24602459
return Statement(statement) if not isinstance(statement, Statement) else statement
24612460

24622461
def postcmd(self, stop: bool, statement: Union[Statement, str]) -> bool:
24632462
"""Hook method executed just after a command is executed by
2464-
:meth:`~cmd2.Cmd.onecmd`.
2463+
[cmd2.Cmd.onecmd][].
24652464
24662465
:param stop: return `True` to request the command loop terminate
24672466
:param statement: subclass of str which also contains the parsed input
24682467
2469-
See :meth:`~cmd2.Cmd.register_postcmd_hook` and :meth:`~cmd2.Cmd.register_cmdfinalization_hook` for more robust ways
2468+
See [cmd2.Cmd.register_postcmd_hook][] and [cmd2.Cmd.register_cmdfinalization_hook][] for more robust ways
24702469
to run hooks after the command is executed. See
2471-
:ref:`features/hooks:Postcommand Hooks` and
2472-
:ref:`features/hooks:Command Finalization Hooks` for more information.
2470+
[Hooks](../features/hooks.md) for more information.
24732471
"""
24742472
return stop
24752473

24762474
def preloop(self) -> None:
2477-
"""Hook method executed once when the :meth:`~.cmd2.Cmd.cmdloop()`
2475+
"""Hook method executed once when the [cmd2.Cmd.cmdloop][]
24782476
method is called.
24792477
2480-
See :meth:`~cmd2.Cmd.register_preloop_hook` for a more robust way
2478+
See [cmd2.Cmd.register_preloop_hook][] for a more robust way
24812479
to run hooks before the command loop begins. See
2482-
:ref:`features/hooks:Application Lifecycle Hooks` for more information.
2480+
[Hooks](../features/hooks.md) for more information.
24832481
"""
24842482
pass
24852483

24862484
def postloop(self) -> None:
2487-
"""Hook method executed once when the :meth:`~.cmd2.Cmd.cmdloop()`
2488-
method is about to return.
2485+
"""Hook method executed once when the [cmd2.Cmd.cmdloop][] method is about to return.
24892486
2490-
See :meth:`~cmd2.Cmd.register_postloop_hook` for a more robust way
2487+
See [cmd2.Cmd.register_postloop_hook][] for a more robust way
24912488
to run hooks after the command loop completes. See
2492-
:ref:`features/hooks:Application Lifecycle Hooks` for more information.
2489+
[Hooks](../features/hooks.md) for more information.
24932490
"""
24942491
pass
24952492

@@ -3028,9 +3025,11 @@ def cmd_func(self, command: str) -> Optional[CommandFunc]:
30283025
30293026
:param command: the name of the command
30303027
3031-
:Example:
3028+
Example:
30323029
3033-
>>> helpfunc = self.cmd_func('help')
3030+
```py
3031+
helpfunc = self.cmd_func('help')
3032+
```
30343033
30353034
helpfunc now contains a reference to the ``do_help`` method
30363035
"""

cmd2/decorators.py

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ def with_category(category: str) -> Callable[[CommandFunc], CommandFunc]:
4343
:param category: the name of the category in which this command should
4444
be grouped when displaying the list of commands.
4545
46-
:Example:
46+
Example:
4747
48-
>>> class MyApp(cmd2.Cmd):
49-
>>> @cmd2.with_category('Text Functions')
50-
>>> def do_echo(self, args)
51-
>>> self.poutput(args)
48+
```py
49+
class MyApp(cmd2.Cmd):
50+
@cmd2.with_category('Text Functions')
51+
def do_echo(self, args)
52+
self.poutput(args)
53+
```
5254
5355
For an alternative approach to categorizing commands using a function, see
54-
:func:`~cmd2.utils.categorize`
56+
[cmd2.utils.categorize][]
5557
"""
5658

5759
def cat_decorator(func: CommandFunc) -> CommandFunc:
@@ -152,12 +154,13 @@ def with_argument_list(
152154
:param preserve_quotes: if ``True``, then argument quotes will not be stripped
153155
:return: function that gets passed a list of argument strings
154156
155-
:Example:
156-
157-
>>> class MyApp(cmd2.Cmd):
158-
>>> @cmd2.with_argument_list
159-
>>> def do_echo(self, arglist):
160-
>>> self.poutput(' '.join(arglist)
157+
Example:
158+
```py
159+
class MyApp(cmd2.Cmd):
160+
@cmd2.with_argument_list
161+
def do_echo(self, arglist):
162+
self.poutput(' '.join(arglist)
163+
```
161164
"""
162165
import functools
163166

@@ -285,38 +288,41 @@ def with_argparser(
285288
:param preserve_quotes: if ``True``, then arguments passed to argparse maintain their quotes
286289
:param with_unknown_args: if true, then capture unknown args
287290
:return: function that gets passed argparse-parsed args in a ``Namespace``
288-
A :class:`cmd2.argparse_custom.Cmd2AttributeWrapper` called ``cmd2_statement`` is included
289-
in the ``Namespace`` to provide access to the :class:`cmd2.Statement` object that was created when
291+
A [cmd2.argparse_custom.Cmd2AttributeWrapper][] called ``cmd2_statement`` is included
292+
in the ``Namespace`` to provide access to the [cmd2.Statement][] object that was created when
290293
parsing the command line. This can be useful if the command function needs to know the command line.
291294
292-
:Example:
293-
294-
>>> parser = cmd2.Cmd2ArgumentParser()
295-
>>> parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
296-
>>> parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
297-
>>> parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
298-
>>> parser.add_argument('words', nargs='+', help='words to print')
299-
>>>
300-
>>> class MyApp(cmd2.Cmd):
301-
>>> @cmd2.with_argparser(parser, preserve_quotes=True)
302-
>>> def do_argprint(self, args):
303-
>>> "Print the options and argument list this options command was called with."
304-
>>> self.poutput(f'args: {args!r}')
305-
306-
:Example with unknown args:
307-
308-
>>> parser = cmd2.Cmd2ArgumentParser()
309-
>>> parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
310-
>>> parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
311-
>>> parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
312-
>>>
313-
>>> class MyApp(cmd2.Cmd):
314-
>>> @cmd2.with_argparser(parser, with_unknown_args=True)
315-
>>> def do_argprint(self, args, unknown):
316-
>>> "Print the options and argument list this options command was called with."
317-
>>> self.poutput(f'args: {args!r}')
318-
>>> self.poutput(f'unknowns: {unknown}')
319-
295+
Example:
296+
297+
```py
298+
parser = cmd2.Cmd2ArgumentParser()
299+
parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
300+
parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
301+
parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
302+
parser.add_argument('words', nargs='+', help='words to print')
303+
304+
class MyApp(cmd2.Cmd):
305+
@cmd2.with_argparser(parser, preserve_quotes=True)
306+
def do_argprint(self, args):
307+
"Print the options and argument list this options command was called with."
308+
self.poutput(f'args: {args!r}')
309+
```
310+
311+
Example with unknown args:
312+
313+
```py
314+
parser = cmd2.Cmd2ArgumentParser()
315+
parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
316+
parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
317+
parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
318+
319+
class MyApp(cmd2.Cmd):
320+
@cmd2.with_argparser(parser, with_unknown_args=True)
321+
def do_argprint(self, args, unknown):
322+
"Print the options and argument list this options command was called with."
323+
self.poutput(f'args: {args!r}')
324+
self.poutput(f'unknowns: {unknown}')
325+
```
320326
"""
321327
import functools
322328

cmd2/history.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ def from_dict(source_dict: Dict[str, Any]) -> 'HistoryItem':
150150

151151

152152
class History(List[HistoryItem]):
153-
"""A list of :class:`~cmd2.history.HistoryItem` objects with additional methods
153+
"""A list of [HistoryItem][cmd2.history.HistoryItem] objects with additional methods
154154
for searching and managing the list.
155155
156-
:class:`~cmd2.Cmd` instantiates this class into the :data:`~cmd2.Cmd.history`
156+
[cmd2.Cmd][] instantiates this class into the `cmd2.Cmd.history`
157157
attribute, and adds commands to it as a user enters them.
158158
159-
See :ref:`features/history:History` for information about the built-in command
159+
See [History](../features/history.md) for information about the built-in command
160160
which allows users to view, search, run, and save previously entered commands.
161161
162162
Developers interested in accessing previously entered commands can use this
@@ -207,7 +207,7 @@ def get(self, index: int) -> HistoryItem:
207207
"""Get item from the History list using 1-based indexing.
208208
209209
:param index: optional item to get
210-
:return: a single :class:`~cmd2.history.HistoryItem`
210+
:return: a single [cmd2.history.HistoryItem][]
211211
"""
212212
if index == 0:
213213
raise IndexError('The first command in history is command 1.')

0 commit comments

Comments
 (0)