A Commander for modern #golang CLI interactions
Cobra is both a library for creating powerful modern CLI applications as well as a program to generate applications and command files.
https://github.com/spf13/cobra
Cobra is a library providing a simple interface to create powerful modern CLI interfaces similar to git & go tools.
Cobra is also an application that will generate your application scaffolding to rapidly develop a Cobra-based application.
Cobra provides:
Easy subcommand-based CLIs:
app server,app fetch, etc.Fully POSIX-compliant flags (including short & long versions)
Nested subcommands
Global, local and cascading flags
Easy generation of applications & commands with
cobra init appname&cobra add cmdnameIntelligent suggestions (
app srver... did you meanapp server?)Automatic help generation for commands and flags
Automatic detailed help for
app help [command]Automatic help flag recognition of
-h,--help, etc.Automatically generated bash autocomplete for your application
Automatically generated man pages for your application
Command aliases so you can change things without breaking them
The flexibility to define your own help, usage, etc.
Optional tight integration with viper for 12-factor apps
Cobra has an exceptionally clean interface and simple design without needless constructors or initialization methods.
Applications built with Cobra commands are designed to be as user-friendly as possible. Flags can be placed before or after the command (as long as a confusing space isn’t provided). Both short and long flags can be used. A command need not even be fully typed. Help is automatically generated and available for the application or for a specific command using either the help command or the --help flag.