If you have command groups in your CLI application so that you have subcommands, you can pass arguments from the group down to the subcommands with the context object. Here’s the pattern:

@click.group()  
@click.argument("arg1", type=click.File("r"))  
@click.option("--option1", default="test")  
@click.pass_context  
def cli(ctx, arg1, option: str):  
    ctx.ensure_object(dict)  
    ctx.obj["arg1"] = arg1  
    ctx.obj["option1"] = option1  
  
  
@click.command()  
@click.argument("subcommand_arg", type=str)
@click.pass_context  
def trigger_training_job(ctx, subcommand_arg):  
    arg1_from_group = ctx.obj["arg1"]

if __name__ == "__main__":  
    cli(obj={})

Source#

Click documentation