
Golang Spf13 Cobra
This teaches you how to build CLI command trees with spf13/cobra, the standard Go library for subcommands, flags, and shell completions. It walks you through the RunE hook chain (PersistentPreRunE is where config initialization lives), args validators like ExactArgs and MatchAll, persistent versus local flags, and ValidArgsFunction for dynamic completions. The testing section is solid: it shows you how to use SetArgs and SetOut to test commands in isolation without touching real stdout. One thing to know: cobra and viper solve different problems (command tree versus config layering), and this skill focuses only on the cobra side. If your CLI is just flags and subcommands with no config files, you only need this.
- skills.sh installs
- 38.6K
- GitHub stars
- 3.8K
- last updated
- Aug 21, 2026
Install
$ npx -y skills add samber/cc-skills-golang --skill golang-spf13-cobra --agent claude-codeInstalls into .claude/skills of the current project.
Files
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 — creating a new CLI from scratch: follow command tree setup, hook wiring, and flag sections sequentially.
- Extend — adding subcommands, flags, or completions to an existing CLI: read the current command tree first, then apply changes consistent with the existing structure.
- Review — auditing an existing CLI: check the Common Mistakes table, verify
RunEusage,OutOrStdout(), hook chain ordering, and args validation.
Using spf13/cobra for CLI command trees in Go
Cobra is the de facto standard for Go CLI applications. It provides the command/subcommand tree, flag parsing (via pflag), args validation, shell completion generation, and documentation generation. It does not handle configuration layering — that's viper's job.
Official Resources:
Sponsors
Details
- Repository
- github.com/samber/cc-skills-golang
- Categories
- Frontend Development, Testing & QA, Git & Pull Requests, Documentation, Code Review & Quality, Go, CLI & Terminal
- First seen
- May 16, 2026
More from samber/cc-skills-golang
All 47- Golang Swagger38.6K
- Golang Graphql38.5K
- Golang Google Wire38.3K
- Golang Spf13 Viper38.3K
- Golang Uber Fx38.1K
- Golang Uber Dig38K
- Golang How To37.9K
- Golang Linter26.5K
- Golang Pkg Go Dev13.3K
- Golang Refactoring12.9K
- Golang Gopls12.5K
- Golang Code Style46.1K
- Golang Testing45.4K
- Golang Error Handling45.3K
- Golang Security44.2K
- Golang Design Patterns43.8K
- Golang Performance43.6K
- Golang Concurrency43.6K
- Golang Context42.7K
- Golang Naming42.5K
- Golang Database42.5K
- Golang Safety42.2K
- Golang Project Layout42.1K
- Golang Documentation42K