golang-spf13-cobra
golang spf13 cobra
What it does
- Build — creating a new CLI from scratch: follow command tree setup, hook wiring, and flag sections sequentially.
- Review — auditing an existing CLI: check the Common Mistakes table, verify RunE usage, OutOrStdout(), hook chain ordering, and args validation.
- pkg.go.dev/github.com/spf13/cobra
- github.com/spf13/cobra
- PersistentPreRunE on the root runs before every subcommand — use it for config init and auth checks.
- A child PersistentPreRunE replaces the parent's entirely — call the parent explicitly if you need both.
- PostRunE runs only if RunE succeeded.
Requirements & configuration
- | Without the other? | Yes — a CLI with flags only needs cobra | Yes — a daemon reading YAML + env needs only viper |
- A child PersistentPreRunE replaces the parent's entirely — call the parent explicitly if you need both.
- require.NoError(t, rootCmd.Execute())
Derived from the skill's own SKILL.md documentation · extracted 2026-07-23
golang-spf13-cobra FAQ
What does the golang-spf13-cobra skill do?
Golang CLI command tree library using spf13/cobra — cobra.Command, RunE vs Run, PersistentPreRunE hook chain, Args validators (NoArgs, ExactArgs, MatchAll, custom), persistent vs local flags, command groups, ValidArgsFunction, RegisterFlagCompletionFunc, ShellCompDirective, usage/help template customization, man-page and markdown doc generation, and testing with SetArgs/SetOut/SetErr. Apply when using or adopting spf13/cobra, or when the codebase imports `github.com/spf13/cobra`. For configuration layering alongside cobra, see the `samber/cc-skills-golang@golang-spf13-viper` skill. For general CLI architecture (project layout, exit codes, signal handling, I/O patterns), see `samber/cc-skills-golang@golang-cli`. Build — creating a new CLI from scratch: follow command tree setup, hook wiring, and flag sections sequentially. Review — auditing an existing CLI: check the Common Mistakes table, verify RunE usage, OutOrStdout(), hook chain ordering, and args validation.
What does golang-spf13-cobra require?
| Without the other? | Yes — a CLI with flags only needs cobra | Yes — a daemon reading YAML + env needs only viper | A child PersistentPreRunE replaces the parent's entirely — call the parent explicitly if you need both. require.NoError(t, rootCmd.Execute())
How do I install golang-spf13-cobra?
Run: npx -y skills add https://github.com/samber/cc-skills-golang --skill golang-spf13-cobra --agent claude-code — the source lives at github.com/samber/cc-skills-golang.
Maintain golang-spf13-cobra?
Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.
[](https://getagentictools.com/skills/samber-cc-skills-golang-golang-spf13-cobra?ref=badge) npx agentictools info skills/samber-cc-skills-golang-golang-spf13-cobra The second line is the CLI lookup for this page — handy in READMEs and docs.