diff --git a/frontends/src/jp/arg_tools.py b/frontends/src/jp/arg_tools.py index 93ab018f..5cee77e1 100644 --- a/frontends/src/jp/arg_tools.py +++ b/frontends/src/jp/arg_tools.py @@ -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 diff --git a/frontends/src/jp/cmd_pubsub.py b/frontends/src/jp/cmd_pubsub.py index 0697583c..c184014c 100644 --- a/frontends/src/jp/cmd_pubsub.py +++ b/frontends/src/jp/cmd_pubsub.py @@ -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 diff --git a/frontends/src/jp/cmd_shell.py b/frontends/src/jp/cmd_shell.py index 9feb92fb..99052875 100644 --- a/frontends/src/jp/cmd_shell.py +++ b/frontends/src/jp/cmd_shell.py @@ -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):