Cobra is a Go framework for building command-line applications from standardized components. A CLI parses commands, arguments, and flags, invokes a matching handler, and presents its output. Cobra packages those responsibilities so applications need not implement flag handling and command plumbing from scratch. section 12.2
A Cobra application is organized as a command tree. The root command is a *cobra.Command; its Use, Short, and Long fields supply usage and help text, while Execute runs the tree once from main. A command's Run function receives the selected command and argument slice, then performs the requested work. section 12.5 section 12.6
Build a command-oriented application incrementally:
- Initialize a project with cobra-cli init, which generates main.go plus cmd/root.go. section 12.3
- Add a command skeleton with cobra-cli add; register it with rootCmd.AddCommand to make it available. section 12.6
- Define local flags for one command or persistent flags inherited by its children, usually in init. section 12.5
- Read flag values in Run and use them to configure or start the underlying service. section 12.6
A worker command
A worker command exposes host, port, name, and datastore-type flags, with long and short forms such as --host and -H. Its Run handler reads those values, creates a worker and API, starts task-related processes, and starts the API server. Built-in help displays the command usage and available flags. section 12.6
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "cube",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely
contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}
Inspect the generated root command to see the minimal command definition: usage text, short and long descriptions, and an optional Run handler. section 12.5
This structure separates operational roles that were previously bundled into one main program. Independent worker and manager commands replace a monolith, while run, stop, status, and node commands provide direct cluster interaction instead of manual curl calls to a manager API. section 12.0 section 12.12

