summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-10 18:58:28 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-10 18:58:28 -0400
commitbc80c994abece4ac1a0540beecd93624d96514b7 (patch)
treea4a60b905859cf3360a099b90ad192f59b3b504f /cmd2
parent50e143c34147ada3f693cdf1b11e4e88fedb3104 (diff)
downloadcmd2-git-bc80c994abece4ac1a0540beecd93624d96514b7.tar.gz
Small refactoring
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/argparse_completer.py27
1 files changed, 11 insertions, 16 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