I'm having a wrapper command that invokes certain command in a loop with period(int value, minutes)
Wrapper command doesn't want to describe arguments of command that is going to be wrapped.
@click.group(name="wrapper-example")
def wrapper_cli():
pass
@wrapper_cli.command("command")
@click.option("--path", type=str, help="example command arg")
def command(path):
click.echo(path)
@wrapper_cli.command(
"run",
context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True,
),
)
@click.option("--period", type=int, help="minutes")
@click.pass_context
def run(ctx: click.Context, period):
# no loop implementantion for clean example
ctx.forward(command)
In this example with forward() I'll get an error, because command() doesn't know about period argument.
With invoke() method, I have to manually parse arguments from wrapper click.Context.args - list that contains raw and unrecognized args. ["--path", "path/"]
Context.args: List[str]
and pass it like:
ctx.invoke(command, **kwargs)
How could I exclude some variables from context to forward command without period argument. Or how could I clearly parse Context.args: List[str], that contains only extra, undefined for wrapper argument values and then use Context.invoke()?