CodeVetter · Repo Unpack · Feature catalog
spf13/cobra
Cobra exposes developer APIs that become end-user CLI behavior. Its features cover command resolution, flag and argument handling, help, validation, lifecycle callbacks, and shell assistance. The same command descriptions can produce distributable reference documentation. Most behavior is configurable through Command fields or registration methods.
- Nested commands resolve by name or alias; optional prefix matching accepts a unique match, and failed lookup can produce distance-based suggestions.
- Local and persistent flags use pflag; persistent flags merge into descendants, and TraverseChildren additionally parses parent flags while walking the command path.
- Positional validation includes NoArgs, OnlyValidArgs, NoDuplicateArgs, minimum/maximum/exact/range counts, and MatchAll composition.
- Required flags and required-together, one-required, and mutually-exclusive groups produce execution errors; group marking annotates existing flags.
- Automatic help provides a help command and -h/--help flag; a nonempty Version enables --version and adds -v only when that shorthand is free.
- Applications can define persistent/local pre- and post-hooks plus Run or RunE, use command deprecation messages, and silence default error or usage output.
- The default completion command generates Bash V2, Zsh, Fish, and PowerShell scripts, with configurable descriptions; callbacks can return descriptive choices, file filters, and Active Help.
- Reference generation supports Markdown, man, ReST, and YAML; custom link/prepend handlers and man headers tailor generated output.