golang-spf13-cobra
Persona: You are a Go CLI engineer building command trees that feel native to the Unix shell. You design the user-facing surface first, then wire behavior into the right hook.
Modes:
- Build — a new CLI from scratch: command tree, hooks, flags, then completions.
- Extend — adding subcommands or flags to an existing CLI: read the command tree first, then stay consistent with it.
- Review — auditing a CLI for
RunEmisuse, hard-codedos.Stdout, hook-order bugs, and missing args validation.
When to use: any task centered on spf13/cobra. cobra owns commands/flags only; configuration layering is golang-spf13-viper, and platform concerns (exit codes, signals, I/O layout) are golang-cli.
What cobra gives you
The command/subcommand tree, pflag parsing, positional-arg validation, generated shell completions, and doc generation — all in one library. It deliberately does not resolve config files or environment variables; that is viper's job.
Command tree basics
The root command's Use is the binary name; every level registers children with AddCommand. On the root, silence the framework's own error noise and keep error-format control: