Modern type-safe Typer CLI patterns with type hints, Enums, and sub-apps. Use when building CLI applications, creating Typer commands, implementing type-safe CLIs, or when user mentions Typer, CLI patterns, type hints, Enums, sub-apps, or command-line interfaces.
/plugin marketplace add vanman2024/cli-builder/plugin install cli-builder@cli-builderThis skill is limited to using the following tools:
QUICKSTART.mdexamples/basic-cli/README.mdexamples/basic-cli/cli.pyexamples/enum-cli/README.mdexamples/enum-cli/cli.pyexamples/factory-cli/README.mdexamples/factory-cli/cli.pyexamples/subapp-cli/README.mdexamples/subapp-cli/cli.pyscripts/convert-argparse.shscripts/generate-cli.shscripts/test-cli.shscripts/validate-skill.shscripts/validate-types.shtemplates/advanced-validation.pytemplates/basic-typed-command.pytemplates/enum-options.pytemplates/sub-app-structure.pytemplates/typer-instance.pyProvides modern type-safe Typer CLI patterns including type hints, Enum usage, sub-app composition, and Typer() instance patterns for building maintainable command-line applications.
Use Python type hints for automatic validation and better IDE support:
import typer
from typing import Optional
from pathlib import Path
app = typer.Typer()
@app.command()
def process(
input_file: Path = typer.Argument(..., help="Input file path"),
output: Optional[Path] = typer.Option(None, help="Output file path"),
verbose: bool = typer.Option(False, "--verbose", "-v"),
count: int = typer.Option(10, help="Number of items to process")
) -> None:
"""Process files with type-safe parameters."""
if verbose:
typer.echo(f"Processing {input_file}")
Use Enums for constrained choices with autocomplete:
from enum import Enum
class OutputFormat(str, Enum):
json = "json"
yaml = "yaml"
text = "text"
@app.command()
def export(
format: OutputFormat = typer.Option(OutputFormat.json, help="Output format")
) -> None:
"""Export with enum-based format selection."""
typer.echo(f"Exporting as {format.value}")
Organize complex CLIs with sub-apps:
app = typer.Typer()
db_app = typer.Typer()
app.add_typer(db_app, name="db", help="Database commands")
@db_app.command("migrate")
def db_migrate() -> None:
"""Run database migrations."""
pass
@db_app.command("seed")
def db_seed() -> None:
"""Seed database with test data."""
pass
Use Typer() instances for better organization and testing:
def create_app() -> typer.Typer:
"""Factory function for creating Typer app."""
app = typer.Typer(
name="myapp",
help="My CLI application",
add_completion=True,
no_args_is_help=True
)
@app.command()
def hello(name: str) -> None:
typer.echo(f"Hello {name}")
return app
app = create_app()
if __name__ == "__main__":
app()
Run the type safety validation:
./scripts/validate-types.sh path/to/cli.py
Checks:
See examples/ for complete working CLIs:
examples/basic-cli/: Simple typed CLIexamples/enum-cli/: Enum-based optionsexamples/subapp-cli/: Multi-command with sub-appsexamples/factory-cli/: Testable Typer factory pattern@app.callback()
def main(
verbose: bool = typer.Option(False, "--verbose", "-v"),
ctx: typer.Context = typer.Context
) -> None:
"""Global options applied to all commands."""
ctx.obj = {"verbose": verbose}
def validate_port(value: int) -> int:
if not 1024 <= value <= 65535:
raise typer.BadParameter("Port must be between 1024-65535")
return value
@app.command()
def serve(port: int = typer.Option(8000, callback=validate_port)) -> None:
"""Serve with validated port."""
pass
from rich.console import Console
console = Console()
@app.command()
def status() -> None:
"""Show status with rich formatting."""
console.print("[bold green]System online[/bold green]")
cli-structure skill for overall CLI architecturetesting-patterns for CLI test coveragepackaging skill for distributiontemplates/scripts/validate-types.sh, scripts/generate-cli.shexamples/*/This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.