spf13/cobra
Build enterprise Go CLI apps with POSIX flags and subcommands
The Go framework powering kubectl, Docker, and GitHub CLI.
Cobra structures complex tools with nested subcommands and flags.
First, structure. Cobra breaks large CLI applications into commands, args, and flags. Subcommands can nest infinitely, letting you build clean patterns like app server start or git clone.
Fully POSIX-compliant flags handle short, long, and cascading options.
Second, flags. Powered by the pflag library, Cobra gives you full POSIX compliance. You can define persistent flags inherited across every subcommand, or local flags scoped to a single action.
Automatic shell completions support Bash, Zsh, Fish, and PowerShell.
Third, developer experience. Cobra generates lightning-fast autocompletions for Bash, Zsh, Fish, and PowerShell out of the box, complete with dynamic suggestions.
Intelligent typo suggestions prevent frustrating command-line mistakes.
Fourth, typo resistance. If a user types a wrong command, Cobra automatically computes Levenshtein distance and suggests the exact command they intended to run.
Cobra powers Kubernetes, Hugo, GitHub CLI, and the Go ecosystem.
With over 44,000 GitHub stars and an Apache license, Cobra is the foundation of modern infrastructure tooling. If you are building a CLI in Go, this is your starting point.