Click framework examples and templates - decorators, nested commands, parameter validation. Use when building Python CLI with Click, implementing command groups, adding CLI options/arguments, validating CLI parameters, creating nested subcommands, or when user mentions Click framework, @click decorators, command-line interface.
This skill provides comprehensive Click framework patterns, templates, and examples for building production-ready Python CLIs.
Read the appropriate template based on complexity:
templates/basic-cli.pytemplates/nested-commands.pytemplates/validators.pyGenerate new Click project:
bash scripts/generate-click-cli.sh <project-name> <cli-type>
Where cli-type is: basic, nested, or advanced
Study complete examples:
examples/complete-example.md - Full-featured CLIexamples/patterns.md - Common patterns and best practicesValidate your Click setup:
bash scripts/validate-click.sh <cli-file.py>
Command Groups:
@click.group()
def cli():
"""Main CLI entry point"""
pass
@cli.command()
def subcommand():
"""A subcommand"""
pass
Options and Arguments:
@click.option('--template', '-t', default='basic', help='Template name')
@click.argument('environment')
def deploy(template, environment):
pass
Nested Groups:
@cli.group()
def config():
"""Configuration management"""
pass
@config.command()
def get():
"""Get config value"""
pass
Parameter Validation:
@click.option('--mode', type=click.Choice(['fast', 'safe', 'rollback']))
@click.option('--count', type=click.IntRange(1, 100))
def command(mode, count):
pass
pip install click)pip install rich)Purpose: Provide Click framework templates and patterns for Python CLI development Load when: Building Click CLIs, implementing command groups, or validating CLI parameters