jp (arg_tools): args is not modified anymore in get_use_args + fixed args returned + parser_args are returned separatly (return is now a tuple)
This commit is contained in:
parent
367bb66a01
commit
23416b5d12
3 changed files with 21 additions and 14 deletions
|
|
@ -47,14 +47,19 @@ def get_use_args(host, args, use, verbose=False, parser=None):
|
|||
@param use(dict[str, str]): arguments to fill if found in parser
|
||||
@param verbose(bool): if True a message will be displayed when argument is used or not
|
||||
@param parser(argparse.ArgumentParser): parser to use
|
||||
@return (tuple[list[str],list[str]]): 2 args lists:
|
||||
- parser args, i.e. given args corresponding to parsers
|
||||
- use args, i.e. generated args from use
|
||||
"""
|
||||
# FIXME: positional args are not handled correclty
|
||||
# if there is more that one, the position is not corrected
|
||||
if parser is None:
|
||||
parser = host.parser
|
||||
|
||||
# we check not optional args to see if there
|
||||
# is a corresonding parser
|
||||
# else USE args would not work correctly (only for current parser)
|
||||
cmd_args = []
|
||||
parser_args = []
|
||||
for arg in args:
|
||||
if arg.startswith('-'):
|
||||
break
|
||||
|
|
@ -62,11 +67,11 @@ def get_use_args(host, args, use, verbose=False, parser=None):
|
|||
parser = get_cmd_choices(arg, parser)
|
||||
except exceptions.NotFound:
|
||||
break
|
||||
cmd_args.append(arg)
|
||||
parser_args.append(arg)
|
||||
|
||||
# we remove command args
|
||||
# they'll be in returned list (use_args)
|
||||
del args[:len(cmd_args)]
|
||||
# post_args are remaning given args,
|
||||
# without the ones corresponding to parsers
|
||||
post_args = args[len(parser_args):]
|
||||
|
||||
opt_args = []
|
||||
pos_args = []
|
||||
|
|
@ -90,4 +95,4 @@ def get_use_args(host, args, use, verbose=False, parser=None):
|
|||
else:
|
||||
opt_args.append(action.option_strings[0])
|
||||
opt_args.append(value)
|
||||
return cmd_args + opt_args + pos_args
|
||||
return parser_args, opt_args + pos_args + post_args
|
||||
|
|
|
|||
|
|
@ -683,12 +683,14 @@ class Search(base.CommandBase):
|
|||
'node': metadata[u'node'],
|
||||
'item': item_elt.get('id'),
|
||||
}
|
||||
args = arg_tools.get_use_args(self.host,
|
||||
self.args.command,
|
||||
use,
|
||||
verbose=self.host.verbosity > 1
|
||||
)
|
||||
cmd_args = sys.argv[0:1] + args + self.args.command
|
||||
# we need to send a copy of self.args.command
|
||||
# else it would be modified
|
||||
parser_args, use_args = arg_tools.get_use_args(self.host,
|
||||
self.args.command,
|
||||
use,
|
||||
verbose=self.host.verbosity > 1
|
||||
)
|
||||
cmd_args = sys.argv[0:1] + parser_args + use_args
|
||||
else:
|
||||
cmd_args = self.args.command
|
||||
|
||||
|
|
|
|||
|
|
@ -182,13 +182,13 @@ class Shell(base.CommandBase, cmd.Cmd):
|
|||
args = self.parse_args(args)
|
||||
# args may be modified by use_args
|
||||
# to remove subparsers from it
|
||||
use_args = arg_tools.get_use_args(self.host,
|
||||
parser_args, use_args = arg_tools.get_use_args(self.host,
|
||||
args,
|
||||
self.use,
|
||||
verbose=self.verbose,
|
||||
parser=self._cur_parser
|
||||
)
|
||||
cmd_args = self.path + use_args + args
|
||||
cmd_args = self.path + parser_args + use_args
|
||||
self.run_cmd(cmd_args)
|
||||
|
||||
def do_use(self, args):
|
||||
|
|
|
|||
Loading…
Reference in a new issue