diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-09-13 18:14:32 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-09-13 18:14:32 -0400 |
commit | 65ed685aad4707e9a8a4a48921d8ca862594d77c (patch) | |
tree | f0dfc510bd9e47e732f3a7a2e24d2065c85c1f12 | |
parent | ed56264038258c24eda81d6f897b7b64cc0dc948 (diff) | |
download | cmd2-git-65ed685aad4707e9a8a4a48921d8ca862594d77c.tar.gz |
Fixed issue where invalid subcommand token was ignored when tab completing help
-rw-r--r-- | cmd2/argparse_completer.py | 5 | ||||
-rw-r--r-- | tests/test_argparse_completer.py | 1 |
2 files changed, 4 insertions, 2 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py index df835e71..89839c25 100644 --- a/cmd2/argparse_completer.py +++ b/cmd2/argparse_completer.py @@ -406,7 +406,7 @@ class AutoCompleter(object): :param endidx: the ending index of the prefix text :return: List of subcommand completions """ - # If our parser has subcommands, we must examine the tokens and check if any reference one. + # If our parser has subcommands, we must examine the tokens and check if they are subcommands # If so, we will let the subcommand's parser handle the rest of the tokens via another AutoCompleter. if self._subcommand_action is not None: for token_index, token in enumerate(tokens[1:], start=1): @@ -416,7 +416,8 @@ class AutoCompleter(object): elif token_index == len(tokens) - 1: # Since this is the last token, we will attempt to complete it return utils.basic_complete(text, line, begidx, endidx, self._subcommand_action.choices) - + else: + break return [] def format_help(self, tokens: List[str]) -> str: diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py index f2a0b01e..c1392676 100644 --- a/tests/test_argparse_completer.py +++ b/tests/test_argparse_completer.py @@ -288,6 +288,7 @@ def test_help(ac_app, command): ('music crea', 'jazz', []), ('music create', 'foo', []), ('fake create', '', []), + ('music fake', '', []) ]) def test_complete_help(ac_app, command, text, completions): line = 'help {} {}'.format(command, text) |