1 # Go CLI Library [![GoDoc](https://godoc.org/github.com/mitchellh/cli?status.png)](https://godoc.org/github.com/mitchellh/cli)
3 cli is a library for implementing powerful command-line interfaces in Go.
4 cli is the library that powers the CLI for
5 [Packer](https://github.com/mitchellh/packer),
6 [Serf](https://github.com/hashicorp/serf),
7 [Consul](https://github.com/hashicorp/consul),
8 [Vault](https://github.com/hashicorp/vault),
9 [Terraform](https://github.com/hashicorp/terraform), and
10 [Nomad](https://github.com/hashicorp/nomad).
14 * Easy sub-command based CLIs: `cli foo`, `cli bar`, etc.
16 * Support for nested subcommands such as `cli foo bar`.
18 * Optional support for default subcommands so `cli` does something
21 * Support for shell autocompletion of subcommands, flags, and arguments
22 with callbacks in Go. You don't need to write any shell code.
24 * Automatic help generation for listing subcommands
26 * Automatic help flag recognition of `-h`, `--help`, etc.
28 * Automatic version flag recognition of `-v`, `--version`.
30 * Helpers for interacting with the terminal, such as outputting information,
31 asking for input, etc. These are optional, you can always interact with the
32 terminal however you choose.
34 * Use of Go interfaces/types makes augmenting various parts of the library a
39 Below is a simple example of creating and running a CLI
48 "github.com/mitchellh/cli"
52 c := cli.NewCLI("app", "1.0.0")
54 c.Commands = map[string]cli.CommandFactory{
55 "foo": fooCommandFactory,
56 "bar": barCommandFactory,
59 exitStatus, err := c.Run()