From 9b1bfab6e2a908d119e46bcc70e98d94739ab4a4 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Tue, 9 Oct 2018 18:10:55 -0400 Subject: Added ability for argcompleter to determine difference between flag and negative number --- cmd2/pyscript_bridge.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'cmd2/pyscript_bridge.py') 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) -- cgit v1.2.1