summaryrefslogtreecommitdiff
path: root/cmd2/argparse_completer.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-10 16:22:47 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-10 16:22:47 -0400
commit782bab855b0ec1d1b9728a322b932f99e6fb3849 (patch)
tree7f02393cd0e0b3352badfc1b376c88e299e64e3d /cmd2/argparse_completer.py
parent60e294ee645e092b8713d5cf60f8797d3685416a (diff)
downloadcmd2-git-782bab855b0ec1d1b9728a322b932f99e6fb3849.tar.gz
Fixed some double-dash handling logic added unit tests
Diffstat (limited to 'cmd2/argparse_completer.py')
-rw-r--r--cmd2/argparse_completer.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py
index 27e7df25..d7ffc180 100644
--- a/cmd2/argparse_completer.py
+++ b/cmd2/argparse_completer.py
@@ -288,19 +288,31 @@ class AutoCompleter(object):
if token_index >= len(tokens) - 1:
is_last_token = True
- # If a remainder action is found, force all future tokens to go to that
+ # If we're in a positional REMAINDER arg, force all future tokens to go to that
if pos_arg_state is not None and pos_arg_state.is_remainder:
consume_positional_argument()
continue
+
+ # If we're in a flag REMAINDER arg, force all future tokens to go to that until a double dash is hit
elif flag_arg_state is not None and flag_arg_state.is_remainder:
skip_remaining_flags = True
if token == '--':
- # End this flag and don't allow any more flags
flag_arg_state = None
else:
consume_flag_argument()
continue
+ # Handle '--' which tells argparse all remaining arguments are non-flags
+ elif token == '--' and not skip_remaining_flags:
+ if is_last_token:
+ # Exit loop and see if -- can be completed into a flag
+ break
+ else:
+ # End the current flag
+ flag_arg_state = None
+ skip_remaining_flags = True
+ continue
+
current_is_positional = False
# Are we consuming flag arguments?
@@ -319,16 +331,8 @@ class AutoCompleter(object):
self._positional_actions[next_pos_arg_index].nargs == argparse.REMAINDER:
skip_remaining_flags = True
- # Handle '--' which tells argparse all remaining arguments are non-flags
- if token == '--' and not skip_remaining_flags:
- if is_last_token:
- # Exit loop and see if -- can be completed into a flag
- break
- else:
- skip_remaining_flags = True
-
# At this point we're no longer consuming flag arguments. Is the current argument a potential flag?
- elif is_potential_flag(token, self._parser) and not skip_remaining_flags:
+ if is_potential_flag(token, self._parser) and not skip_remaining_flags:
# Reset flag arg state but not positional tracking because flags can be
# interspersed anywhere between positionals
flag_arg_state = None