diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-23 16:35:17 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-23 16:35:17 -0400 |
commit | 5fd8e00010e068eb0632b6cb20860a18774181a5 (patch) | |
tree | 89d2613b84e00c608c91fbf9ee1f401678cdae9a /docs | |
parent | ecf154f1b13e41644fefd3db624aae1d8c1e0d2a (diff) | |
download | cmd2-git-5fd8e00010e068eb0632b6cb20860a18774181a5.tar.gz |
Documented CompletionError class
Diffstat (limited to 'docs')
-rw-r--r-- | docs/features/completion.rst | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/features/completion.rst b/docs/features/completion.rst index 3a2c50e0..0735893a 100644 --- a/docs/features/completion.rst +++ b/docs/features/completion.rst @@ -34,6 +34,24 @@ 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 +------------------------------------ +There are times when tab completion fails and a message needs to be reported to +the user. These include the following example cases: + +- Reading a database to retrieve a tab completion data set failed +- A previous command line argument that determines the data set being completed + is invalid +- Tab completion hints + +``cmd2`` provides the :class:`cmd2.utils.CompletionError` exception class for +this capability. If an error occurs in which it is more desirable to display +a message than a stack trace, then raise a ``CompletionError``. By default, the +message displays in red like an error. However, ``CompletionError`` has a +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 ---------------------------------------- |