Skip to content

Commit 65ed685

Browse files
committed
Fixed issue where invalid subcommand token was ignored when tab completing help
1 parent ed56264 commit 65ed685

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

cmd2/argparse_completer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def complete_subcommand_help(self, tokens: List[str], text: str, line: str, begi
406406
:param endidx: the ending index of the prefix text
407407
:return: List of subcommand completions
408408
"""
409-
# If our parser has subcommands, we must examine the tokens and check if any reference one.
409+
# If our parser has subcommands, we must examine the tokens and check if they are subcommands
410410
# If so, we will let the subcommand's parser handle the rest of the tokens via another AutoCompleter.
411411
if self._subcommand_action is not None:
412412
for token_index, token in enumerate(tokens[1:], start=1):
@@ -416,7 +416,8 @@ def complete_subcommand_help(self, tokens: List[str], text: str, line: str, begi
416416
elif token_index == len(tokens) - 1:
417417
# Since this is the last token, we will attempt to complete it
418418
return utils.basic_complete(text, line, begidx, endidx, self._subcommand_action.choices)
419-
419+
else:
420+
break
420421
return []
421422

422423
def format_help(self, tokens: List[str]) -> str:

tests/test_argparse_completer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ def test_help(ac_app, command):
288288
('music crea', 'jazz', []),
289289
('music create', 'foo', []),
290290
('fake create', '', []),
291+
('music fake', '', [])
291292
])
292293
def test_complete_help(ac_app, command, text, completions):
293294
line = 'help {} {}'.format(command, text)

0 commit comments

Comments
 (0)