diff options
-rw-r--r-- | cmd2/argparse_custom.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/cmd2/argparse_custom.py b/cmd2/argparse_custom.py index 668f41d6..3f1cb212 100644 --- a/cmd2/argparse_custom.py +++ b/cmd2/argparse_custom.py @@ -81,8 +81,7 @@ Tab Completion: parser.add_argument('-o', '--options', completer_method=cmd2.Cmd.path_complete) - In all cases in which function/methods are passed you can use functools.partial() to prepopulate - values of the underlying function. + You can use functools.partial() to prepopulate values of the underlying choices and completer functions/methods. Example: This says to call path_complete with a preset value for its path_filter argument. @@ -90,6 +89,11 @@ Tab Completion: path_filter=lambda path: os.path.isdir(path)) parser.add_argument('-o', '--options', choices_method=completer_method) + Of the 5 tab-completion parameters, choices is the only one where argparse validates user input against items + in the choices list. This is because the other 4 parameters are meant to tab complete data sets that are viewed + as dynamic. Therefore it is up to the user to validate if the user has typed an acceptable value for these + arguments. + 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 |