Mercurial > libervia-backend
changeset 2317:f4e05600577b
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)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Jul 2017 22:49:55 +0200 |
parents | 7b448ac50a69 |
children | ddb67c186f61 |
files | frontends/src/jp/arg_tools.py frontends/src/jp/cmd_pubsub.py frontends/src/jp/cmd_shell.py |
diffstat | 3 files changed, 21 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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
--- 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):