Skip to content

Commit 6deb39d

Browse files
committed
Updated tab completion documentation
1 parent 5fd8e00 commit 6deb39d

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,18 @@ Instructions for implementing each feature follow.
171171
- And also provide help hints for values associated with these flags
172172
- Experiment with the [argprint.py](https://github.com/python-cmd2/cmd2/blob/master/examples/arg_print.py) example
173173
using the **oprint** and **pprint** commands to get a feel for how this works
174+
- `basic_complete` helper method for tab completion against a list
174175
- `path_complete` helper method provides flexible tab completion of file system paths
175176
- See the [paged_output.py](https://github.com/python-cmd2/cmd2/blob/master/examples/paged_output.py) example for a simple use case
176177
- See the [python_scripting.py](https://github.com/python-cmd2/cmd2/blob/master/examples/python_scripting.py) example for a more full-featured use case
177-
- `flag_based_complete` helper method for tab completion based on a particular flag preceding the token being completed
178-
- See the [basic_completion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/basic_completion.py) example for a demonstration of how to use this feature
179-
- `index_based_complete` helper method for tab completion based on a fixed position in the input string
180-
- See the [basic_completion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/basic_completion.py) example for a demonstration of how to use this feature
181-
- `basic_complete` helper method for tab completion against a list
182178
- `delimiter_complete` helper method for tab completion against a list but each match is split on a delimiter
183179
- See the [basic_completion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/basic_completion.py) example for a demonstration of how to use this feature
180+
- `flag_based_complete` helper method for tab completion based on a particular flag preceding the token being completed
181+
- `index_based_complete` helper method for tab completion based on a fixed position in the input string
182+
- See the [basic_completion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/basic_completion.py) example for a demonstration of how to use these features
183+
- `flag_based_complete()` and `index_based_complete()` are basic methods and should only be used if you are not
184+
familiar with argparse. The recommended approach for tab completing positional tokens and flags is to use
185+
argparse-based completion
184186
- `cmd2` in combination with `argparse` also provide several advanced capabilities for automatic tab completion
185187
- See the [argparse_completion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/argparse_completion.py) example for more info
186188

docs/features/completion.rst

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,42 @@ similar to the following to your class which inherits from :class:`cmd2.Cmd`::
3434
complete_bar = functools.partialmethod(cmd2.Cmd.path_complete, path_filter=os.path.isdir)
3535

3636

37-
Raising exceptions during completion
37+
Included Tab Completion Functions
38+
---------------------------------
39+
``cmd2`` provides the following tab completion functions
40+
41+
- :attr:`cmd2.utils.basic_complete` - helper method for tab completion against
42+
a list
43+
- :attr:`cmd2.Cmd.path_complete` - helper method provides flexible tab
44+
completion of file system paths
45+
46+
- See the paged_output_ example for a simple use case
47+
- See the python_scripting_ example for a more full-featured use case
48+
49+
- :attr:`cmd2.Cmd.delimiter_complete` - helper method for tab completion
50+
against a list but each match is split on a delimiter
51+
52+
- See the basic_completion_ example for a demonstration of how to use
53+
this feature
54+
55+
- :attr:`cmd2.Cmd.flag_based_complete` - helper method for tab completion based
56+
on a particular flag preceding the token being completed
57+
- :attr:`cmd2.Cmd.index_based_complete` - helper method for tab completion
58+
based on a fixed position in the input string
59+
60+
- See the basic_completion_ example for a demonstration of how to use these
61+
features
62+
- ``flag_based_complete()`` and ``index_based_complete()`` are basic
63+
methods and should only be used if you are not familiar with argparse.
64+
The recommended approach for tab completing positional tokens and flags
65+
is to use argparse-based_ completion.
66+
67+
.. _paged_output: https://github.com/python-cmd2/cmd2/blob/master/examples/paged_output.py
68+
.. _python_scripting: https://github.com/python-cmd2/cmd2/blob/master/examples/python_scripting.py
69+
.. _basic_completion: https://github.com/python-cmd2/cmd2/blob/master/examples/basic_completion.py
70+
71+
72+
Raising Exceptions During Completion
3873
------------------------------------
3974
There are times when tab completion fails and a message needs to be reported to
4075
the user. These include the following example cases:
@@ -52,10 +87,12 @@ member called ``apply_style``. Set this False if the error style should not be
5287
applied. For instance, ``ArgparseCompleter`` sets it to False when displaying
5388
completion hints.
5489

55-
Tab Completion Using Argparse Decorators
90+
.. _argparse-based:
91+
92+
Tab Completion Using argparse Decorators
5693
----------------------------------------
5794

58-
When using one the Argparse-based :ref:`api/decorators:cmd2.decorators`,
95+
When using one the argparse-based :ref:`api/decorators:cmd2.decorators`,
5996
``cmd2`` provides automatic tab completion of flag names.
6097

6198
Tab completion of argument values can be configured by using one of five

examples/basic_completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
A simple example demonstrating how to enable tab completion by assigning a completer function to do_* commands.
55
This also demonstrates capabilities of the following completer features included with cmd2:
66
- CompletionError exceptions
7-
- delimiter_completer()
7+
- delimiter_complete()
88
- flag_based_complete() (see note below)
99
- index_based_complete() (see note below)
1010

0 commit comments

Comments
 (0)