- Home
- Skills
- Vanman2024
- Cli Builder
- Cli Patterns
cli-patterns_skill
- Python
0
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill vanman2024/cli-builder --skill cli-patterns- SKILL.md8.2 KB
Overview
This skill provides lightweight, battle-tested Go CLI patterns built on urfave/cli v2 for fast, maintainable command-line tools. It focuses on minimal dependencies, clear command organization, and practical patterns for flags, subcommands, hooks, and shared context. Use it to prototype or productionize Go CLIs with fewer boilerplate and smaller binaries than heavier frameworks.
How this skill works
The skill offers reusable templates and scripts to scaffold single-command and multi-command CLIs, flag examples, command categories, and lifecycle hooks. It wires Before/After hooks for initialization and cleanup, demonstrates environment variable fallbacks and required-flag validation, and shows patterns for passing shared context (DB connections, config, API clients) across commands. Generation and utility scripts automate adding commands, flags, and validating standard CLI hygiene.
When to use it
- Building a new Go CLI where small binary size and fast compilation matter
- Creating command hierarchies with subcommands, aliases, and categories
- Implementing robust flag patterns (env fallbacks, defaults, required flags)
- Adding lifecycle hooks for setup/teardown and shared context between commands
- Migrating from Cobra or other frameworks to a simpler urfave/cli-based codebase
Best practices
- Start simple: scaffold a single-command CLI and add complexity incrementally
- Use kebab-case for command names and consistent flag naming (-v/--verbose, -c/--config)
- Provide environment variable fallbacks for important flags and sensible defaults
- Validate flags and configuration in Before hooks, not in action handlers
- Group related commands into categories when a command set grows (>5) and provide concise help and examples
Example use cases
- Database management tool with migrate/seed/backup commands and connection validation hooks
- Deployment automation CLI with build/test/deploy/rollback categories and shared deployment context
- API client CLI exposing get/post/put/delete with global auth token and base-URL flags
- File processing utility with commands for convert/validate/optimize and input/output format flags
- Migration guide examples showing how to map Cobra or Click patterns to urfave/cli idioms
FAQ
urfave/cli is lighter, compiles faster, produces smaller binaries, and requires less boilerplate while remaining production-ready for many use cases.
Where should I validate flags and load config?
Run validation and configuration loading in a Before hook so errors surface before action logic executes and shared state can be injected into context.