@@ -31,3 +31,50 @@ similar to the following to your class which inherits from ``cmd2.Cmd``::
3131
3232 # Make sure you have an "import functools" somewhere at the top
3333 complete_bar = functools.partialmethod(cmd2.Cmd.path_complete, path_filter=os.path.isdir)
34+
35+
36+ Tab Completion Using Argparse Decorators
37+ ----------------------------------------
38+
39+ When using one the Argparse-based :ref: `decorators `, ``cmd2 `` provides
40+ automatic tab-completion of flag names.
41+
42+ Tab-completion of argument values can be configured by using one of five
43+ parameters to ``argparse.ArgumentParser.add_argument() ``
44+
45+ - ``choices ``
46+ - ``choices_function `` / ``choices_method ``
47+ - ``completer_function `` / ``completer_method ``
48+
49+ See the arg_decorators _ or colors _ example for a demonstration of how to
50+ use the ``choices `` parameter. See the tab_autocompletion _ example for a
51+ demonstration of how to use the ``choices_function `` and ``choices_method ``
52+ parameters. See the arg_decorators _ or tab_autocompletion _ example for a
53+ demonstration of how to use the ``completer_method `` parameter.
54+
55+ When tab-completing flags and/or argument values for a ``cmd2 `` command using
56+ one of these decorators, ``cmd2 `` keeps track of state so that once a flag has
57+ already previously been provided, it won't attempt to tab-complete it again.
58+ When no completion results exists, a hint for the current argument will be
59+ displayed to help the user.
60+
61+ .. _arg_decorators : https://github.com/python-cmd2/cmd2/blob/master/examples/arg_decorators.py
62+ .. _colors : https://github.com/python-cmd2/cmd2/blob/master/examples/colors.py
63+ .. _tab_autocompletion : https://github.com/python-cmd2/cmd2/blob/master/examples/tab_autocompletion..py
64+
65+
66+ CompletionItem For Providing Extra Context
67+ ------------------------------------------
68+
69+ When tab-completing things like a unique ID from a database, it can often be
70+ beneficial to provide the user with some extra context about the item being
71+ completed, such as a description. To facilitate this, ``cmd2 `` defines the
72+ ``CompletionItem `` class which can be returned from any of the 4 completion
73+ functions: ``choices_function ``, ``choices_method ``, ``completion_function ``,
74+ or ``completion_method ``.
75+
76+ .. autoclass :: cmd2.argparse_custom.CompletionItem
77+ :members:
78+
79+ See the tab_autocompletion _ example or the implementation of the built-in
80+ **set ** command for demonstration of how this is used.
0 commit comments