• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..08-Mar-2019-

LICENSEH A D08-Mar-201915.6 KiB355256

MakefileH A D08-Mar-2019534 2112

README.mdH A D08-Mar-20191.6 KiB6545

cli.goH A D08-Mar-201912.2 KiB467281

command.goH A D08-Mar-20191.6 KiB4813

command_mock.goH A D08-Mar-2019826 4326

help.goH A D08-Mar-20191.9 KiB8057

ui.goH A D08-Mar-20194.1 KiB188128

ui_colored.goH A D08-Mar-20191.6 KiB7052

ui_concurrent.goH A D08-Mar-2019877 5538

ui_mock.goH A D08-Mar-20191.1 KiB6547

ui_writer.goH A D08-Mar-2019349 1912

README.md

1# Go CLI Library [![GoDoc](https://godoc.org/github.com/mitchellh/cli?status.png)](https://godoc.org/github.com/mitchellh/cli)
2
3cli is a library for implementing powerful command-line interfaces in Go.
4cli 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).
11
12## Features
13
14* Easy sub-command based CLIs: `cli foo`, `cli bar`, etc.
15
16* Support for nested subcommands such as `cli foo bar`.
17
18* Optional support for default subcommands so `cli` does something
19  other than error.
20
21* Automatic help generation for listing subcommands
22
23* Automatic help flag recognition of `-h`, `--help`, etc.
24
25* Automatic version flag recognition of `-v`, `--version`.
26
27* Helpers for interacting with the terminal, such as outputting information,
28  asking for input, etc. These are optional, you can always interact with the
29  terminal however you choose.
30
31* Use of Go interfaces/types makes augmenting various parts of the library a
32  piece of cake.
33
34## Example
35
36Below is a simple example of creating and running a CLI
37
38```go
39package main
40
41import (
42	"log"
43	"os"
44
45	"github.com/mitchellh/cli"
46)
47
48func main() {
49	c := cli.NewCLI("app", "1.0.0")
50	c.Args = os.Args[1:]
51	c.Commands = map[string]cli.CommandFactory{
52		"foo": fooCommandFactory,
53		"bar": barCommandFactory,
54	}
55
56	exitStatus, err := c.Run()
57	if err != nil {
58		log.Println(err)
59	}
60
61	os.Exit(exitStatus)
62}
63```
64
65