About this project
Cobra is a library for creating powerful modern CLI applications in Go. It provides a simple interface for building command-line interfaces similar to git and go tools, and is used by projects such as Kubernetes, Hugo, and GitHub CLI.
Key capabilities described in the README:
- Easy subcommand-based CLIs such as `app server` and `app fetch`
- Fully POSIX-compliant flags, including short and long versions
- Nested subcommands
- Global, local, and cascading flags
- Intelligent suggestions for mistyped commands (e.g., suggesting `app server` for `app srver`)
- Automatic help generation for commands and flags
- Grouping help for subcommands
- Automatic recognition of help flags such as `-h` and `--help`
- Automatically generated shell autocomplete for bash, zsh, fish, and powershell
- Automatically generated man pages
- Command aliases
- Flexibility to define custom help and usage output
- Optional integration with viper for 12-factor apps
Cobra is built around commands, arguments, and flags. Commands represent actions, args are things, and flags modify those actions. The recommended pattern is `APPNAME VERB NOUN --ADJECTIVE` or `APPNAME COMMAND ARG --FLAG`.
Installation is done with `go get -u github.com/spf13/cobra@latest`, then importing `github.com/spf13/cobra`. A companion tool, `cobra-cli`, can be installed with `go install github.com/spf13/cobra-cli@latest` to generate application scaffolding and command files.
Flag functionality is provided by the pflag library, a fork of the Go standard flag package that adds POSIX compliance while maintaining the same interface. Cobra is released under the Apache 2.0 license.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.