summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-04-23 17:34:04 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-04-23 17:34:04 -0400
commit6deb39d75f785e40daaa14ef033bf5797f42944f (patch)
treeba1d1995f2f8b312e431e63062562fc339009339
parent5fd8e00010e068eb0632b6cb20860a18774181a5 (diff)
downloadcmd2-git-6deb39d75f785e40daaa14ef033bf5797f42944f.tar.gz
Updated tab completion documentation
-rwxr-xr-xREADME.md12
-rw-r--r--docs/features/completion.rst43
-rwxr-xr-xexamples/basic_completion.py2
3 files changed, 48 insertions, 9 deletions
diff --git a/README.md b/README.md
index ce2fdb7c..32b8e7fa 100755
--- a/README.md
+++ b/README.md
@@ -171,16 +171,18 @@ Instructions for implementing each feature follow.
- And also provide help hints for values associated with these flags
- Experiment with the [argprint.py](https://github.com/python-cmd2/cmd2/blob/master/examples/arg_print.py) example
using the **oprint** and **pprint** commands to get a feel for how this works
+ - `basic_complete` helper method for tab completion against a list
- `path_complete` helper method provides flexible tab completion of file system paths
- See the [paged_output.py](https://github.com/python-cmd2/cmd2/blob/master/examples/paged_output.py) example for a simple use case
- 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
- - `flag_based_complete` helper method for tab completion based on a particular flag preceding the token being completed
- - 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
- - `index_based_complete` helper method for tab completion based on a fixed position in the input string
- - 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
- - `basic_complete` helper method for tab completion against a list
- `delimiter_complete` helper method for tab completion against a list but each match is split on a delimiter
- 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
+ - `flag_based_complete` helper method for tab completion based on a particular flag preceding the token being completed
+ - `index_based_complete` helper method for tab completion based on a fixed position in the input string
+ - 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
+ - `flag_based_complete()` and `index_based_complete()` are basic methods and should only be used if you are not
+ familiar with argparse. The recommended approach for tab completing positional tokens and flags is to use
+ argparse-based completion
- `cmd2` in combination with `argparse` also provide several advanced capabilities for automatic tab completion
- See the [argparse_completion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/argparse_completion.py) example for more info
diff --git a/docs/features/completion.rst b/docs/features/completion.rst
index 0735893a..c15ceb13 100644
--- a/docs/features/completion.rst
+++ b/docs/features/completion.rst
@@ -34,7 +34,42 @@ similar to the following to your class which inherits from :class:`cmd2.Cmd`::
complete_bar = functools.partialmethod(cmd2.Cmd.path_complete, path_filter=os.path.isdir)
-Raising exceptions during completion
+Included Tab Completion Functions
+---------------------------------
+``cmd2`` provides the following tab completion functions
+
+- :attr:`cmd2.utils.basic_complete` - helper method for tab completion against
+ a list
+- :attr:`cmd2.Cmd.path_complete` - helper method provides flexible tab
+ completion of file system paths
+
+ - See the paged_output_ example for a simple use case
+ - See the python_scripting_ example for a more full-featured use case
+
+- :attr:`cmd2.Cmd.delimiter_complete` - helper method for tab completion
+ against a list but each match is split on a delimiter
+
+ - See the basic_completion_ example for a demonstration of how to use
+ this feature
+
+- :attr:`cmd2.Cmd.flag_based_complete` - helper method for tab completion based
+ on a particular flag preceding the token being completed
+- :attr:`cmd2.Cmd.index_based_complete` - helper method for tab completion
+ based on a fixed position in the input string
+
+ - See the basic_completion_ example for a demonstration of how to use these
+ features
+ - ``flag_based_complete()`` and ``index_based_complete()`` are basic
+ methods and should only be used if you are not familiar with argparse.
+ The recommended approach for tab completing positional tokens and flags
+ is to use argparse-based_ completion.
+
+.. _paged_output: https://github.com/python-cmd2/cmd2/blob/master/examples/paged_output.py
+.. _python_scripting: https://github.com/python-cmd2/cmd2/blob/master/examples/python_scripting.py
+.. _basic_completion: https://github.com/python-cmd2/cmd2/blob/master/examples/basic_completion.py
+
+
+Raising Exceptions During Completion
------------------------------------
There are times when tab completion fails and a message needs to be reported to
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
applied. For instance, ``ArgparseCompleter`` sets it to False when displaying
completion hints.
-Tab Completion Using Argparse Decorators
+.. _argparse-based:
+
+Tab Completion Using argparse Decorators
----------------------------------------
-When using one the Argparse-based :ref:`api/decorators:cmd2.decorators`,
+When using one the argparse-based :ref:`api/decorators:cmd2.decorators`,
``cmd2`` provides automatic tab completion of flag names.
Tab completion of argument values can be configured by using one of five
diff --git a/examples/basic_completion.py b/examples/basic_completion.py
index 9523ac67..f33029c9 100755
--- a/examples/basic_completion.py
+++ b/examples/basic_completion.py
@@ -4,7 +4,7 @@
A simple example demonstrating how to enable tab completion by assigning a completer function to do_* commands.
This also demonstrates capabilities of the following completer features included with cmd2:
- CompletionError exceptions
-- delimiter_completer()
+- delimiter_complete()
- flag_based_complete() (see note below)
- index_based_complete() (see note below)