diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-10-09 18:10:55 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-10-09 18:10:55 -0400 |
commit | 9b1bfab6e2a908d119e46bcc70e98d94739ab4a4 (patch) | |
tree | ede6d98da79a3ea2bebcbea03a468df449a38104 /cmd2/pyscript_bridge.py | |
parent | ad3ca3263e2a3552b010d17458a51697f405720f (diff) | |
download | cmd2-git-9b1bfab6e2a908d119e46bcc70e98d94739ab4a4.tar.gz |
Added ability for argcompleter to determine difference between flag and negative number
Diffstat (limited to 'cmd2/pyscript_bridge.py')
-rw-r--r-- | cmd2/pyscript_bridge.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py index 037c7a77..11a2cbb3 100644 --- a/cmd2/pyscript_bridge.py +++ b/cmd2/pyscript_bridge.py @@ -12,7 +12,7 @@ import functools import sys from typing import List, Callable, Optional -from .argparse_completer import _RangeAction +from .argparse_completer import _RangeAction, token_resembles_flag from .utils import namedtuple_with_defaults, StdSim, quote_string_if_needed # Python 3.4 require contextlib2 for temporarily redirecting stderr and stdout @@ -225,9 +225,9 @@ class ArgparseFunctor: if isinstance(value, List) or isinstance(value, tuple): for item in value: item = str(item).strip() - if self._parser._parse_optional(item) is not None: - raise ValueError('Value provided for {} ({}) appears to be an optional'. - format(action.dest, item)) + if token_resembles_flag(item, self._parser): + raise ValueError('{} appears to be a flag and should be supplied as a keyword argument ' + 'to the function.'.format(item)) item = quote_string_if_needed(item) cmd_str[0] += '{} '.format(item) @@ -240,8 +240,9 @@ class ArgparseFunctor: else: value = str(value).strip() - if self._parser._parse_optional(value) is not None: - raise ValueError('Value provided for {} ({}) appears to be an optional'.format(action.dest, value)) + if token_resembles_flag(value, self._parser): + raise ValueError('{} appears to be a flag and should be supplied as a keyword argument ' + 'to the function.'.format(value)) value = quote_string_if_needed(value) cmd_str[0] += '{} '.format(value) |