Click CLI With Subcommands

Build a CLI tool with Click subcommands options and help for consistent command interfaces.

PythonCli Tooling

Code

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

@cli.command()
@click.option('--name', required=True, help='User name')
@click.option('--verbose', is_flag=True)
def greet(name, verbose):
    msg = f'Hello, {name}!'
    if verbose:
        click.echo(msg)
    else:
        click.echo(msg)

@cli.command()
@click.argument('path', type=click.Path(exists=True))
def process(path):
    click.echo(f'Processing {path}')