diff options
Diffstat (limited to 'cmd2/argparse_completer.py')
-rwxr-xr-x | cmd2/argparse_completer.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py index 6c291e86..6e53a518 100755 --- a/cmd2/argparse_completer.py +++ b/cmd2/argparse_completer.py @@ -70,8 +70,10 @@ import re as _re from .rl_utils import rl_force_redisplay -ACTION_ARG_CHOICES = 'arg_choices' +# attribute that can optionally added to an argparse argument (called an Action) to +# define the completion choices for the argument. You may provide a Collection or a Function. +ACTION_ARG_CHOICES = 'arg_choices' class _RangeAction(object): def __init__(self, nargs: Union[int, str, Tuple[int, int], None]): @@ -222,6 +224,7 @@ class AutoCompleter(object): # if there are choices defined, record them in the arguments dictionary if action.choices is not None: self._arg_choices[action.dest] = action.choices + # if completion choices are tagged on the action, record them elif hasattr(action, ACTION_ARG_CHOICES): action_arg_choices = getattr(action, ACTION_ARG_CHOICES) self._arg_choices[action.dest] = action_arg_choices @@ -412,9 +415,8 @@ class AutoCompleter(object): return completion_results def complete_command_help(self, tokens: List[str], text: str, line: str, begidx: int, endidx: int) -> List[str]: + """Supports the completion of sub-commands for commands thhrough the cmd2 help command.""" for idx, token in enumerate(tokens): - is_last_token = idx > len(tokens) - 1 - if idx >= self._token_start_index: if self._positional_completers: # For now argparse only allows 1 sub-command group per level |