samber avatar

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-code

Installs 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 RunE usage, 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
1jakubkrehel avatarbetter-colorsjakubkrehel/skillsOKLCH color space and color usage for web projects. Convert hex/rgb/hsl to oklch, generate palettes, check contrast, handle gamut boundaries, theme with Tailwin38.4Kskills.sh installs
2samber avatargolang-uber-fxsamber/cc-skills-golangGolang application framework using uber-go/fx — fx.New, fx.Provide, fx.Invoke, fx.Module, fx.Lifecycle hooks, fx.Annotate (name/group/As), fx.Decorate, fx.Suppl38.1Kskills.sh installs
3clerk avatarclerk-cliclerk/skillsOperate the Clerk CLI (`clerk` binary) for authentication, user/org/session management, impersonation, local webhook testing, deploy verification, instance conf35.8Kskills.sh installs
4jimliu avatarbaoyu-post-to-wechatjimliu/baoyu-skillsPosts content to WeChat Official Account (微信公众号) via API or Chrome CDP. Supports article posting (文章) with HTML, markdown, or plain text input, and image-text p34.8Kskills.sh installs
5addyosmani avatarcore-web-vitalsaddyosmani/web-quality-skillsOptimize Core Web Vitals (LCP, INP, CLS) for better page experience and search ranking. Use when asked to "improve Core Web Vitals", "fix LCP", "reduce CLS", "o34.4Kskills.sh installs
6jimliu avatarbaoyu-infographicjimliu/baoyu-skillsGenerate professional infographics with 21 layout types and 22 visual styles. Analyzes content, recommends layout×style combinations, and generates publication-33.4Kskills.sh installs