summaryrefslogtreecommitdiff
path: root/cmd2/argparse_completer.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-10 16:37:26 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-10 16:37:26 -0400
commit734fee811025a8f1a68d985907649937ac42a629 (patch)
tree73779e7a6537ad5491afac0ec973cf62bcec2c3f /cmd2/argparse_completer.py
parent782bab855b0ec1d1b9728a322b932f99e6fb3849 (diff)
downloadcmd2-git-734fee811025a8f1a68d985907649937ac42a629.tar.gz
Small refactors and doc updates
Diffstat (limited to 'cmd2/argparse_completer.py')
-rw-r--r--cmd2/argparse_completer.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py
index d7ffc180..a4b25ea5 100644
--- a/cmd2/argparse_completer.py
+++ b/cmd2/argparse_completer.py
@@ -125,17 +125,17 @@ class AutoCompleter(object):
elif self.action.nargs is None:
self.min = 1
self.max = 1
- elif self.action.nargs == argparse.ONE_OR_MORE:
- self.min = 1
- self.max = float('inf')
+ elif self.action.nargs == argparse.OPTIONAL:
+ self.min = 0
+ self.max = 1
self.variable = True
elif self.action.nargs == argparse.ZERO_OR_MORE or self.action.nargs == argparse.REMAINDER:
self.min = 0
self.max = float('inf')
self.variable = True
- elif self.action.nargs == argparse.OPTIONAL:
- self.min = 0
- self.max = 1
+ elif self.action.nargs == argparse.ONE_OR_MORE:
+ self.min = 1
+ self.max = float('inf')
self.variable = True
else:
self.min = self.action.nargs
@@ -404,9 +404,8 @@ class AutoCompleter(object):
consume_flag_argument()
# To allow completion of the final token, we only do the following on preceding tokens
- if not is_last_token:
- if flag_arg_state is not None and flag_arg_state.min is not None:
- flag_arg_state.needed = flag_arg_state.count < flag_arg_state.min
+ if not is_last_token and flag_arg_state is not None:
+ flag_arg_state.needed = flag_arg_state.count < flag_arg_state.min
# Here we're done parsing all of the prior arguments. We know what the next argument is.
@@ -493,7 +492,7 @@ class AutoCompleter(object):
def complete_command_help(self, tokens: List[str], text: str, line: str, begidx: int, endidx: int) -> List[str]:
"""
- Supports the completion of sub-command names
+ Supports cmd2's help command in the completion of sub-command names
:param tokens: command line tokens
:param text: the string prefix we are attempting to match (all returned matches must begin with it)
:param line: the current input line with leading whitespace removed