diff frontends/src/jp/arg_tools.py @ 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 8d9bd5d77336
children 5129a0506739
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