diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-12 00:53:11 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-12 00:53:11 -0400 |
commit | 6a9e3d9b72118443253e41a4cd06b59363b70e7d (patch) | |
tree | a9e922de5a685e45c25c32c634410c878d0eff5c /cmd2/argparse_completer.py | |
parent | 4149be49d639bd7f4bedf08e4890e546af4bc1a5 (diff) | |
download | cmd2-git-6a9e3d9b72118443253e41a4cd06b59363b70e7d.tar.gz |
Fixed issue where flags did not always complete while in a positional
Diffstat (limited to 'cmd2/argparse_completer.py')
-rw-r--r-- | cmd2/argparse_completer.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py index 3afa0774..89cfeb0a 100644 --- a/cmd2/argparse_completer.py +++ b/cmd2/argparse_completer.py @@ -299,14 +299,11 @@ class AutoCompleter(object): self._positional_actions[next_pos_arg_index].nargs == argparse.REMAINDER: skip_remaining_flags = True - # Now try to complete the last token - last_token = tokens[-1] - # Check if we are completing a flag name. This check ignores strings with a length of one, like '-'. # This is because that could be the start of a negative number which may be a valid completion for # the current argument. We will handle the completion of flags that start with only one prefix # character (-f) at the end. - if starts_like_flag(last_token, self._parser) and not skip_remaining_flags: + if starts_like_flag(text, self._parser) and not skip_remaining_flags: if flag_arg_state is not None and flag_arg_state.count < flag_arg_state.min: self._print_unfinished_flag_error(flag_arg_state) return [] @@ -360,14 +357,14 @@ class AutoCompleter(object): if completion_results: return completion_results - # Otherwise, if we haven't completed this flag, then print a hint - elif pos_arg_state.count < pos_arg_state.min: + # Otherwise, print a hint if text isn't possibly the start of a flag + elif not (len(text) == 1 and text[0] in self._parser.prefix_chars) or skip_remaining_flags: self._print_arg_hint(pos_arg_state.action) return [] - # If we've gotten this far, then last_token did not complete for a flag name, flag value, or positional. - # It's possible last_token is a single flag-prefix character like '-'. Try completing it against flag names. - if last_token and not skip_remaining_flags: + # If we've gotten this far, then text did not complete for a flag name, flag value, or positional. + # If text is a single flag-prefix character like '-', try completing it against flag names. + if len(text) == 1 and text[0] in self._parser.prefix_chars and not skip_remaining_flags: return self._complete_flags(text, line, begidx, endidx, matched_flags) return completion_results |