Currently it is not possible to pass params attribute to @command() and @group() decorators.
This would be really simple implementation, which can be seen in this forked commit
Although, this allows to mix decorator and class patterns, there are a few advantages as well:
- Share same option spec between (sub)commands (consider CRUD subcommands which all have
--force option, except read)
It can be done with nested decorators, which hurt readability
- Take advantage of IDE auto-completion when using
Option() class instead of decorator (PEP-612 would resolve this, but it requires python >=3.10)
If this is something to be considered, I can follow up with a PR.
Example usage:
import click
@click.group()
def crud():
...
write_args = [
click.Option(['--force'], is_flag=True)
]
@crud.command(params=write_args)
def create():
...
@crud.command(params=write_args)
@click.option('--create', is_flag=True) # Should this be appended or prepended to `write_args`?
def update():
...
@crud.command(params=write_args)
def delete():
...
@crud.command()
def read():
...
Currently it is not possible to pass
paramsattribute to@command()and@group()decorators.This would be really simple implementation, which can be seen in this forked commit
Although, this allows to mix decorator and class patterns, there are a few advantages as well:
--forceoption, exceptread)It can be done with nested decorators, which hurt readability
Option()class instead of decorator (PEP-612 would resolve this, but it requires python >=3.10)If this is something to be considered, I can follow up with a PR.
Example usage: