diff options
-rw-r--r-- | cmd2/argparse_custom.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/cmd2/argparse_custom.py b/cmd2/argparse_custom.py index 5071989d..59a00f4c 100644 --- a/cmd2/argparse_custom.py +++ b/cmd2/argparse_custom.py @@ -102,6 +102,20 @@ Tab Completion: set_completer_function(action, func) set_completer_method(action, method) + There are times when what's being tab completed is determined by a previous argument on the command line. + In theses cases, Autocompleter can pass an argparse Namespace that maps the command line tokens up through the + one being completed to their argparse argument. To receive this Namespace, your choices/completer function + should have an argument called arg_tokens. + + Example: + def my_choices_method(self, arg_tokens) + def my_completer_method(self, text, line, begidx, endidx, arg_tokens) + + All members of the arg_tokens Namespace are lists, even if a particular argument expects only 1 token. Since + AutoCompleter is for tab completion, it does not convert the tokens to their actual argument types or validate + their values. All tokens are stored in the Namespace 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. + 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 |