diff options
-rw-r--r-- | cmd2/argparse_completer.py | 27 | ||||
-rw-r--r-- | tests/test_argparse_completer.py | 4 |
2 files changed, 13 insertions, 18 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py index a4b25ea5..1393db0e 100644 --- a/cmd2/argparse_completer.py +++ b/cmd2/argparse_completer.py @@ -236,14 +236,11 @@ class AutoCompleter(object): def consume_flag_argument() -> None: """Consuming token as a flag argument""" - if flag_arg_state is None: - return - # if the token does not look like a new flag, then count towards flag arguments - if not is_potential_flag(token, self._parser): + if flag_arg_state is not None and not is_potential_flag(token, self._parser): flag_arg_state.count += 1 - # does this complete an option item for the flag + # Does this complete an option item for the flag? arg_choices = self._resolve_choices_for_arg(flag_arg_state.action) # If the current token isn't the one being completed and it's in the flag @@ -254,19 +251,17 @@ class AutoCompleter(object): def consume_positional_argument() -> None: """Consuming token as positional argument""" - if pos_arg_state is None: - return - - pos_arg_state.count += 1 + if pos_arg_state is not None: + pos_arg_state.count += 1 - # does this complete an option item for the positional - arg_choices = self._resolve_choices_for_arg(pos_arg_state.action) + # Does this complete an option item for the positional? + arg_choices = self._resolve_choices_for_arg(pos_arg_state.action) - # If the current token isn't the one being completed and it's in the positional - # argument's autocomplete list, then track that we've used it already. - if not is_last_token and token in arg_choices: - consumed_arg_values.setdefault(pos_arg_state.action.dest, []) - consumed_arg_values[pos_arg_state.action.dest].append(token) + # If the current token isn't the one being completed and it's in the positional + # argument's autocomplete list, then track that we've used it already. + if not is_last_token and token in arg_choices: + consumed_arg_values.setdefault(pos_arg_state.action.dest, []) + consumed_arg_values[pos_arg_state.action.dest].append(token) # This next block of processing tries to parse all parameters before the last parameter. # We're trying to determine what specific argument the current cursor position should be diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py index 5c6b750f..7a7559f4 100644 --- a/tests/test_argparse_completer.py +++ b/tests/test_argparse_completer.py @@ -42,8 +42,8 @@ def completer_function(text: str, line: str, begidx: int, endidx: int) -> List[s # noinspection PyMethodMayBeStatic,PyUnusedLocal class AutoCompleteTester(cmd2.Cmd): """Cmd2 app that exercises AutoCompleter class""" - def __init__(self): - super().__init__() + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) ############################################################################################################ # Begin code related to help and command name completion |