python
import click
@click.command()
@click.option('--name', prompt='Your name', help='The person to greet.')
def hello(name):
click.echo(f"Hello, {name}!")
if __name__ == '__main__':
hello()
python
import click
@click.group()
def cli():
pass
@cli.command()
@click.option('--name', prompt='Your name', help='The person to greet.')
def hello(name):
click.echo(f"Hello, {name}!")
@cli.command()
@click.option('--count', default=1, help='Number of times to greet.')
def greet(count):
for _ in range(count):
click.echo("Hello, there!")
if __name__ == '__main__':
cli()
python
import click
import configparser
config = configparser.ConfigParser()
@click.group()
@click.option('--config-file', default='config.ini', help='Path to the config file.')
@click.pass_context
def cli(ctx, config_file):
config.read(config_file)
ctx.obj = {
'name': config.get('settings', 'name')
}
@cli.command()
@click.pass_context
def hello(ctx):
click.echo(f"Hello, {ctx.obj['name']}!")
if __name__ == '__main__':
cli()