talira

Go library for modern CLI apps with subcommands, POSIX flags and generated completions

open sourceApache-2.0self-hostablefree

Cobra is a Go library for building command-line applications with subcommands, like git and the go tool. It gives you nested subcommands, POSIX-compliant short and long flags (global, local and cascading), suggestions for mistyped commands, generated help, shell completions for bash, zsh, fish and PowerShell, man pages, command aliases and pre- and post-run hooks, and it pairs with Viper for configuration from files and environment variables. The cobra-cli generator scaffolds a new app. Kubernetes, Hugo and GitHub CLI are built with it. Steve Francia created it.

Problems it solves

  • build a Go CLI with subcommands like git
  • parse flags and subcommands in a Go command-line tool
  • generate shell completions and man pages for my Go CLI
  • scaffold a new Go command-line application

Features

  • nested subcommands
  • POSIX-compliant global, local and cascading flags
  • suggestions for mistyped commands
  • generated help, man pages and shell completions (bash, zsh, fish, PowerShell)
  • command aliases and pre/post-run hooks
  • Viper integration for 12-factor configuration
  • cobra-cli generator

Alternatives

The same job

These do what Cobra does.

  1. urfave/cli A declarative, simple, fast, and fun package for building command line tools in Go

Compare Cobra with the top 3