Skip to content

Commit 4a136b3

Browse files
committed
Allowing negative number values when checking for optional prefix characters
1 parent 8be2db4 commit 4a136b3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

cmd2/pyscript_bridge.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,13 @@ def _run(self):
204204
def has_optional_prefix(arg: str) -> bool:
205205
"""
206206
Checks if an argument value begins with prefix characters intended for argparse optional values
207+
Allows anything that appears to be a negative number
207208
:param arg: argument value being checked
208209
:return: True if arg begins with one of the prefix characters
209210
"""
211+
if self._parser._negative_number_matcher.match(arg):
212+
return False
213+
210214
for char in self._parser.prefix_chars:
211215
if arg.startswith(char):
212216
return True
@@ -232,14 +236,11 @@ def process_argument(action, value):
232236
# was the argument a flag?
233237
if action.option_strings:
234238
cmd_str[0] += '{} '.format(action.option_strings[0])
235-
is_flag = True
236-
else:
237-
is_flag = False
238239

239240
if isinstance(value, List) or isinstance(value, tuple):
240241
for item in value:
241242
item = str(item).strip()
242-
if not is_flag and has_optional_prefix(item):
243+
if has_optional_prefix(item):
243244
raise ValueError('Value provided for {} ({}) appears to be an optional'.
244245
format(action.dest, item))
245246
item = quote_string_if_needed(item)
@@ -254,7 +255,7 @@ def process_argument(action, value):
254255

255256
else:
256257
value = str(value).strip()
257-
if not is_flag and has_optional_prefix(value):
258+
if has_optional_prefix(value):
258259
raise ValueError('Value provided for {} ({}) appears to be an optional'.format(action.dest, value))
259260
value = quote_string_if_needed(value)
260261
cmd_str[0] += '{} '.format(value)

0 commit comments

Comments
 (0)