# HG changeset patch # User Goffi # Date 1499546995 -7200 # Node ID f4e05600577b02f29cc3641fa0d30406c88022a9 # Parent 7b448ac50a6995f1c59bc5b5441258b3f37b7619 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) diff -r 7b448ac50a69 -r f4e05600577b frontends/src/jp/arg_tools.py --- a/frontends/src/jp/arg_tools.py Sat Jul 08 21:54:24 2017 +0200 +++ b/frontends/src/jp/arg_tools.py Sat Jul 08 22:49:55 2017 +0200 @@ -47,14 +47,19 @@ @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 @@ 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 @@ 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 -r 7b448ac50a69 -r f4e05600577b frontends/src/jp/cmd_pubsub.py --- a/frontends/src/jp/cmd_pubsub.py Sat Jul 08 21:54:24 2017 +0200 +++ b/frontends/src/jp/cmd_pubsub.py Sat Jul 08 22:49:55 2017 +0200 @@ -683,12 +683,14 @@ '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 -r 7b448ac50a69 -r f4e05600577b frontends/src/jp/cmd_shell.py --- a/frontends/src/jp/cmd_shell.py Sat Jul 08 21:54:24 2017 +0200 +++ b/frontends/src/jp/cmd_shell.py Sat Jul 08 22:49:55 2017 +0200 @@ -182,13 +182,13 @@ 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):