Lightweight Go CLI patterns using urfave/cli. Use when building CLI tools, creating commands with flags, implementing subcommands, adding before/after hooks, organizing command categories, or when user mentions Go CLI, urfave/cli, cobra alternatives, CLI flags, CLI categories.
View on GitHubvanman2024/cli-builder
cli-builder
plugins/cli-builder/skills/cli-patterns/SKILL.md
January 22, 2026
Select agents to install to:
npx add-skill https://github.com/vanman2024/cli-builder/blob/main/plugins/cli-builder/skills/cli-patterns/SKILL.md -a claude-code --skill cli-patternsInstallation paths:
.claude/skills/cli-patterns/# CLI Patterns Skill Lightweight Go CLI patterns using urfave/cli for fast, simple command-line applications. ## Overview Provides battle-tested patterns for building production-ready CLI tools in Go using urfave/cli v2. Focus on simplicity, speed, and maintainability over complex frameworks like Cobra. ## Why urfave/cli? - **Lightweight**: Minimal dependencies, small binary size - **Fast**: Quick compilation, fast execution - **Simple API**: Easy to learn, less boilerplate than Cobra - **Production-ready**: Used by Docker, Nomad, and many other tools - **Native Go**: Feels like standard library code ## Core Patterns ### 1. Basic CLI Structure Use `templates/basic-cli.go` for simple single-command CLIs: - Main command with flags - Help text generation - Error handling - Exit codes ### 2. Subcommands Use `templates/subcommands-cli.go` for multi-command CLIs: - Command hierarchy (app → command → subcommand) - Shared flags across commands - Command aliases - Command categories ### 3. Flags and Options Use `templates/flags-demo.go` for comprehensive flag examples: - String, int, bool, duration flags - Required vs optional flags - Default values - Environment variable fallbacks - Flag aliases (short and long forms) - Custom flag types ### 4. Command Categories Use `templates/categories-cli.go` for organized command groups: - Group related commands - Better help text organization - Professional CLI UX - Examples: database commands, deploy commands, etc. ### 5. Before/After Hooks Use `templates/hooks-cli.go` for lifecycle management: - Global setup (before all commands) - Global cleanup (after all commands) - Per-command setup/teardown - Initialization and validation - Resource management ### 6. Context and State Use `templates/context-cli.go` for shared state: - Pass configuration between commands - Share database connections - Manage API clients - Context values ## Scripts ### Generation Scripts **`scripts/generate-basic.sh <app-name>`** - Generates