Handle flags with args correctly with split=False.
This commit is contained in:
parent
3579caf1ff
commit
451df7bbf4
@ -44,6 +44,7 @@ class Command:
|
||||
parser: The ArgumentParser to use to parse this command.
|
||||
special_params: A dict with the names of the special parameters as
|
||||
values.
|
||||
flags_with_args: A list of flags which take an argument.
|
||||
_type_conv: A mapping of conversion functions for arguments.
|
||||
_name_conv: A mapping of argument names to parameter names.
|
||||
_needs_js: Whether the command needs javascript enabled
|
||||
@ -92,6 +93,7 @@ class Command:
|
||||
self.pos_args = []
|
||||
self.special_params = {'count': None, 'win_id': None}
|
||||
self.desc = None
|
||||
self.flags_with_args = []
|
||||
self._type_conv = {}
|
||||
self._name_conv = {}
|
||||
self._inspect_func()
|
||||
@ -290,6 +292,8 @@ class Command:
|
||||
args.append(long_flag)
|
||||
args.append(short_flag)
|
||||
self.opt_args[param.name] = long_flag, short_flag
|
||||
if param.kind == inspect.Parameter.KEYWORD_ONLY:
|
||||
self.flags_with_args.append(param.name)
|
||||
else:
|
||||
args.append(name)
|
||||
self.pos_args.append((param.name, name))
|
||||
|
@ -262,12 +262,17 @@ class CommandRunner(QObject):
|
||||
# second split: ['--foo', '-v', 'bar baz']
|
||||
# (maxsplit=2)
|
||||
split_args = split.simple_split(argstr, keep=keep)
|
||||
flag_arg_count = 0
|
||||
for i, arg in enumerate(split_args):
|
||||
arg = arg.strip()
|
||||
if not arg.startswith('-'):
|
||||
if arg.startswith('-'):
|
||||
if arg.lstrip('-') in self._cmd.flags_with_args:
|
||||
flag_arg_count += 1
|
||||
else:
|
||||
self._args = []
|
||||
maxsplit = i + self._cmd.maxsplit + flag_arg_count
|
||||
args = split.simple_split(argstr, keep=keep,
|
||||
maxsplit=i + self._cmd.maxsplit)
|
||||
maxsplit=maxsplit)
|
||||
for s in args:
|
||||
# remove quotes and replace \" by "
|
||||
s = re.sub(r"""(^|[^\\])["']""", r'\1', s)
|
||||
|
Loading…
Reference in New Issue
Block a user