Skip to content

Commit 94f3c4c

Browse files
authored
Merge pull request #903 from python-cmd2/completion_docs
Revise completion docs. Fixes #800. Updates #765.
2 parents 405eb79 + 4d5c928 commit 94f3c4c

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

docs/features/completion.rst

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
Completion
22
==========
33

4-
``cmd2`` adds tab completion of file system paths for all built-in commands
5-
where it makes sense, including:
4+
:class:`cmd2.Cmd` adds tab completion of file system paths for all built-in
5+
commands where it makes sense, including:
66

7-
- ``edit``
8-
- ``run_pyscript``
9-
- ``run_script``
10-
- ``shell``
7+
- :ref:`features/builtin_commands:edit`
8+
- :ref:`features/builtin_commands:run_pyscript`
9+
- :ref:`features/builtin_commands:run_script`
10+
- :ref:`features/builtin_commands:shell`
1111

12-
``cmd2`` also adds tab completion of shell commands to the ``shell`` command.
12+
:class:`cmd2.Cmd` also adds tab completion of shell commands to the
13+
:ref:`features/builtin_commands:shell` command.
1314

14-
Additionally, it is trivial to add identical file system path completion to
15-
your own custom commands. Suppose you have defined a custom command ``foo`` by
16-
implementing the ``do_foo`` method. To enable path completion for the ``foo``
17-
command, then add a line of code similar to the following to your class which
18-
inherits from ``cmd2.Cmd``::
15+
It is easy to add identical file system path completion to your own custom
16+
commands. Suppose you have defined a custom command ``foo`` by implementing
17+
the ``do_foo`` method. To enable path completion for the ``foo`` command, then
18+
add a line of code similar to the following to your class which inherits from
19+
:class:`cmd2.Cmd`::
1920

2021
complete_foo = cmd2.Cmd.path_complete
2122

@@ -27,7 +28,7 @@ The built-in logic allows for a few more advanced path completion capabilities,
2728
such as cases where you only want to match directories. Suppose you have a
2829
custom command ``bar`` implemented by the ``do_bar`` method. You can enable
2930
path completion of directories only for this command by adding a line of code
30-
similar to the following to your class which inherits from ``cmd2.Cmd``::
31+
similar to the following to your class which inherits from :class:`cmd2.Cmd`::
3132

3233
# Make sure you have an "import functools" somewhere at the top
3334
complete_bar = functools.partialmethod(cmd2.Cmd.path_complete, path_filter=os.path.isdir)
@@ -40,19 +41,19 @@ When using one the Argparse-based :ref:`api/decorators:cmd2.decorators`,
4041
``cmd2`` provides automatic tab completion of flag names.
4142

4243
Tab completion of argument values can be configured by using one of five
43-
parameters to ``argparse.ArgumentParser.add_argument()``
44+
parameters to :meth:`argparse.ArgumentParser.add_argument`
4445

4546
- ``choices``
46-
- ``choices_function`` / ``choices_method``
47-
- ``completer_function`` / ``completer_method``
47+
- ``choices_function`` or ``choices_method``
48+
- ``completer_function`` or ``completer_method``
4849

4950
See the arg_decorators_ or colors_ example for a demonstration of how to
5051
use the ``choices`` parameter. See the argparse_completion_ example for a
5152
demonstration of how to use the ``choices_function`` and ``choices_method``
5253
parameters. See the arg_decorators_ or argparse_completion_ example for a
5354
demonstration of how to use the ``completer_method`` parameter.
5455

55-
When tab completing flags and/or argument values for a ``cmd2`` command using
56+
When tab completing flags or argument values for a ``cmd2`` command using
5657
one of these decorators, ``cmd2`` keeps track of state so that once a flag has
5758
already previously been provided, it won't attempt to tab complete it again.
5859
When no completion results exists, a hint for the current argument will be
@@ -74,4 +75,9 @@ any of the 4 completion functions: ``choices_function``, ``choices_method``,
7475
``completion_function``, or ``completion_method``.
7576

7677
See the argparse_completion_ example or the implementation of the built-in
77-
**set** command for demonstration of how this is used.
78+
:meth:`~cmd2.Cmd.do_set` command for demonstration of how this is used.
79+
80+
For More Information
81+
--------------------
82+
83+
See :mod:`cmd2.argparse_custom` for more details.

0 commit comments

Comments
 (0)