summaryrefslogtreecommitdiff
path: root/cmd2/pyscript_bridge.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-10-07 14:19:27 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-10-07 14:19:27 -0400
commit4a136b3cfb3d7177303cb6f67edccb7b72fa91b1 (patch)
tree5d30d09174b049f6e4a5a25cd2ccb58a6db25752 /cmd2/pyscript_bridge.py
parent8be2db480a7445fe18af7aba4fbd78922c747de3 (diff)
downloadcmd2-git-4a136b3cfb3d7177303cb6f67edccb7b72fa91b1.tar.gz
Allowing negative number values when checking for optional prefix characters
Diffstat (limited to 'cmd2/pyscript_bridge.py')
-rw-r--r--cmd2/pyscript_bridge.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py
index 30fdb170..5b2d3e46 100644
--- a/cmd2/pyscript_bridge.py
+++ b/cmd2/pyscript_bridge.py
@@ -204,9 +204,13 @@ class ArgparseFunctor:
def has_optional_prefix(arg: str) -> bool:
"""
Checks if an argument value begins with prefix characters intended for argparse optional values
+ Allows anything that appears to be a negative number
:param arg: argument value being checked
:return: True if arg begins with one of the prefix characters
"""
+ if self._parser._negative_number_matcher.match(arg):
+ return False
+
for char in self._parser.prefix_chars:
if arg.startswith(char):
return True
@@ -232,14 +236,11 @@ class ArgparseFunctor:
# was the argument a flag?
if action.option_strings:
cmd_str[0] += '{} '.format(action.option_strings[0])
- is_flag = True
- else:
- is_flag = False
if isinstance(value, List) or isinstance(value, tuple):
for item in value:
item = str(item).strip()
- if not is_flag and has_optional_prefix(item):
+ if has_optional_prefix(item):
raise ValueError('Value provided for {} ({}) appears to be an optional'.
format(action.dest, item))
item = quote_string_if_needed(item)
@@ -254,7 +255,7 @@ class ArgparseFunctor:
else:
value = str(value).strip()
- if not is_flag and has_optional_prefix(value):
+ if has_optional_prefix(value):
raise ValueError('Value provided for {} ({}) appears to be an optional'.format(action.dest, value))
value = quote_string_if_needed(value)
cmd_str[0] += '{} '.format(value)