pythonintermediate
Click CLI Command Group
Build professional CLI tools with Click using command groups, options, arguments, and help text.
pythonPress ⌘/Ctrl + Shift + C to copy
import click
@click.group()
@click.version_option(version="1.0.0")
def cli():
"""SnippetsLab CLI — manage your snippet collection."""
pass
@cli.command()
@click.argument("name")
@click.option("--lang", "-l", default="python", help="Programming language")
@click.option("--difficulty", "-d", type=click.Choice(["beginner", "intermediate", "advanced"]))
def create(name: str, lang: str, difficulty: str | None):
"""Create a new snippet with NAME."""
click.echo(f"Creating snippet: {name} ({lang})")
if difficulty:
click.echo(f" Difficulty: {difficulty}")
@cli.command()
@click.option("--tag", "-t", multiple=True, help="Filter by tag")
@click.option("--limit", default=10, show_default=True)
def search(tag: tuple[str, ...], limit: int):
"""Search snippets by tag."""
click.echo(f"Searching (tags={tag}, limit={limit})")
if __name__ == "__main__":
cli()Use Cases
- Developer tools
- Admin scripts
- Data pipeline runners
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
pythonbeginner
CLI Tool with argparse
Build a professional CLI tool with subcommands, typed arguments, environment variable fallbacks, and help text.
Best for: Developer tooling
#cli#argparse
javaintermediate
CLI Argument Parser
Parse command-line arguments with flags, options, positional args, and help text without external libraries.
Best for: Command-line tool argument parsing
#java#cli
scalaintermediate
Command-Line Application
Build CLI applications with argument parsing, interactive prompts, and formatted output.
Best for: Command-line tool development
#scala#cli
pythonbeginner
Rich Progress Bar for CLI
Display beautiful progress bars and status spinners in CLI applications using the Rich library.
Best for: Data processing scripts
#cli#rich