import click
_global_options = [
click.option('-v', '--verbose', count=True, default=0, help='Verbose output.'),
click.option('-n', '--dry-run', is_flag=True, default=False, help='Dry-run mode.')
]
def common_options(func):
for option in reversed(_global_options):
func = option(func)
return func
# Standard way using it as a decorator
@click.group()
@common_options
def cli():
pass
# Using it as a function
@click.group()
def cli():
pass
common_options(cli)