diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-09-23 20:57:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-23 20:57:26 -0400 |
commit | b72edb07d59d45d4006dc596218a52d54396378a (patch) | |
tree | 9875db04a91bbcef2815a32113268ffeed7e39cf /cmd2/argparse_custom.py | |
parent | 27a0adbe53c7cdeda240c325a6f59b7cca0e7bfd (diff) | |
parent | 88db3b44fb0b28b01b73376e1d2822d6c5995856 (diff) | |
download | cmd2-git-b72edb07d59d45d4006dc596218a52d54396378a.tar.gz |
Merge pull request #781 from python-cmd2/CompletionError
CompletionError class
Diffstat (limited to 'cmd2/argparse_custom.py')
-rw-r--r-- | cmd2/argparse_custom.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/cmd2/argparse_custom.py b/cmd2/argparse_custom.py index 940d6064..f7dbc8a3 100644 --- a/cmd2/argparse_custom.py +++ b/cmd2/argparse_custom.py @@ -94,7 +94,7 @@ Tab Completion: as dynamic. Therefore it is up to the developer to validate if the user has typed an acceptable value for these arguments. - The following functions exist in cases where you may want to manually add choice providing function/methods to + The following functions exist in cases where you may want to manually a add choice-providing function/method to an existing argparse action. For instance, in __init__() of a custom action class. set_choices_function(action, func) @@ -116,6 +116,13 @@ Tab Completion: their values. All tokens are stored in the dictionary as the raw strings provided on the command line. It is up to the developer to determine if the user entered the correct argument type (e.g. int) and validate their values. +CompletionError Class: + Raised during tab-completion operations to report any sort of error you want printed by the AutoCompleter + + Example use 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 + CompletionItem Class: This class was added to help in cases where uninformative data is being tab completed. For instance, tab completing ID numbers isn't very helpful to a user without context. Returning a list of CompletionItems @@ -221,6 +228,17 @@ def generate_range_error(range_min: int, range_max: Union[int, float]) -> str: return err_str +class CompletionError(Exception): + """ + Raised during tab-completion operations to report any sort of error you want printed by the AutoCompleter + + Example use 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 + """ + pass + + class CompletionItem(str): """ Completion item with descriptive text attached |