Python CLI with Click
Build a command-line tool in Python using Click with subcommands, option parsing, colored output, progress bars, and configuration file loading. Includes.
Code
import click
@click.group()
def cli():
pass
@cli.command()
@click.argument('name')
@click.option('--format', '-f', default='json', help='Output format')
def build(name, format):
click.echo(click.style(f'Building {name} ({format})', fg='green'))
@cli.command()
@click.option('--verbose', is_flag=True)
def deploy(verbose):
if verbose:
click.echo('Deploying with verbose output...')
click.echo('Done!')
if __name__ == '__main__':
cli()