diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-08-22 13:22:53 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-08-22 13:22:53 -0400 |
commit | 6af36b1753e0f70597def2210bd2b1279a44c188 (patch) | |
tree | d969ba525dc6040eeeef154809f2342be4a2b329 /cmd2/argparse_completer.py | |
parent | f1bf0ae07769630977f803ef685ce41d68cdfe6a (diff) | |
download | cmd2-git-6af36b1753e0f70597def2210bd2b1279a44c188.tar.gz |
AutoCompleter now passes parsed_args to all choices and completer functions
Diffstat (limited to 'cmd2/argparse_completer.py')
-rw-r--r-- | cmd2/argparse_completer.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py index 8565db77..20cc08c3 100644 --- a/cmd2/argparse_completer.py +++ b/cmd2/argparse_completer.py @@ -449,29 +449,25 @@ class AutoCompleter(object): setattr(parsed_args, action.dest, tokens) parsed_args.__parser__ = self._parser + # Arguments to completer/choices functions + args = [] + kwargs = {'parsed_args': parsed_args} + # Check if the argument uses a specific tab completion function to provide its choices if isinstance(arg_choices, ChoicesCallable) and arg_choices.is_completer: - args = [] if arg_choices.is_method: args.append(self._cmd2_app) - args.extend([text, line, begidx, endidx]) - if arg_choices.pass_parsed_args: - args.append(parsed_args) - - results = arg_choices.to_call(*args) + results = arg_choices.to_call(*args, **kwargs) # Otherwise use basic_complete on the choices else: # Check if the choices come from a function if isinstance(arg_choices, ChoicesCallable) and not arg_choices.is_completer: - args = [] if arg_choices.is_method: args.append(self._cmd2_app) - if arg_choices.pass_parsed_args: - args.append(parsed_args) - arg_choices = arg_choices.to_call(*args) + arg_choices = arg_choices.to_call(*args, **kwargs) # Since arg_choices can be any iterable type, convert to a list arg_choices = list(arg_choices) |