Get params sent to a subcommand of a click.group()

Viewed 2743

If I have a click.group() with multiple sub-commands, is there a way that I can get the command line arguments passed to those sub-commands within the group itself?

I know you can go from the group downwards via the context, and I know that I can use a callback function that will execute before the command, but I didn't know if there was a better way to do this than use a callback.

An example:

@click.group()
def cli():
    pass

@cli.command()
@click.argument('task')
@click.argument('task_id')
def sync(task, task_id):
    click.echo('Synching: {}'.format(task))

In this example, is there any way to get task or task_id in the group method?

1 Answers
Related