diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-10-07 17:33:05 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-10-07 17:33:05 -0400 |
commit | ad3ca3263e2a3552b010d17458a51697f405720f (patch) | |
tree | c0510c0b8c51d066823c58b8cb0b5bd0643c8098 | |
parent | 4a136b3cfb3d7177303cb6f67edccb7b72fa91b1 (diff) | |
download | cmd2-git-ad3ca3263e2a3552b010d17458a51697f405720f.tar.gz |
Use argparser to determine if a token looks like an optional
-rw-r--r-- | cmd2/pyscript_bridge.py | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py index 5b2d3e46..037c7a77 100644 --- a/cmd2/pyscript_bridge.py +++ b/cmd2/pyscript_bridge.py @@ -201,21 +201,6 @@ class ArgparseFunctor: # reconstruct the cmd2 command from the python call cmd_str = [''] - 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 - return False - def process_argument(action, value): if isinstance(action, argparse._CountAction): if isinstance(value, int): @@ -240,7 +225,7 @@ class ArgparseFunctor: if isinstance(value, List) or isinstance(value, tuple): for item in value: item = str(item).strip() - if has_optional_prefix(item): + if self._parser._parse_optional(item) is not None: raise ValueError('Value provided for {} ({}) appears to be an optional'. format(action.dest, item)) item = quote_string_if_needed(item) @@ -255,7 +240,7 @@ class ArgparseFunctor: else: value = str(value).strip() - if has_optional_prefix(value): + if self._parser._parse_optional(value) is not None: 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) |