idf.py: Add positional arguments to subcommands
@@ -599,6 +599,13 @@ def init_cli():
self.callback = wrapped_callback
+ class Argument(click.Argument):
+ """Positional argument"""
+
+ def __init__(self, **kwargs):
+ names = kwargs.pop("names")
+ super(Argument, self).__init__(names, **kwargs)
+
class CLI(click.MultiCommand):
"""Action list contains all actions with options available for CLI"""
@@ -630,8 +637,12 @@ def init_cli():
# Actions
for name, action in action_list.get("actions", {}).items():
+ arguments = action.pop("arguments", [])
options = action.pop("options", [])
+ if arguments is None:
+ arguments = []
+
if options is None:
options = []
@@ -639,6 +650,9 @@ def init_cli():
for alias in [name] + action.get("aliases", []):
self.commands_with_aliases[alias] = name
+ for argument_args in arguments:
+ self._actions[name].params.append(Argument(**argument_args))
+
for option_args in options:
option_args["param_decls"] = option_args.pop("names")
self._actions[name].params.append(click.Option(**option_args))
