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

..17-May-2021-

.travis.ymlH A D17-May-2021171 1913

LICENSEH A D17-May-202115.6 KiB355256

MakefileH A D17-May-2021377 189

README.mdH A D17-May-20211.7 KiB6847

autocomplete.goH A D17-May-20211.1 KiB4427

cli.goH A D17-May-202120.7 KiB729422

command.goH A D17-May-20212.4 KiB6820

command_mock.goH A D17-May-20211.3 KiB6440

go.modH A D17-May-2021425 1512

go.sumH A D17-May-20212.1 KiB2322

help.goH A D17-May-20211.9 KiB8057

ui.goH A D17-May-20214.1 KiB188128

ui_colored.goH A D17-May-20211.8 KiB7455

ui_concurrent.goH A D17-May-2021877 5538

ui_mock.goH A D17-May-20212.2 KiB11785

ui_writer.goH A D17-May-2021349 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* Support for shell autocompletion of subcommands, flags, and arguments
22  with callbacks in Go. You don't need to write any shell code.
23
24* Automatic help generation for listing subcommands
25
26* Automatic help flag recognition of `-h`, `--help`, etc.
27
28* Automatic version flag recognition of `-v`, `--version`.
29
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.
33
34* Use of Go interfaces/types makes augmenting various parts of the library a
35  piece of cake.
36
37## Example
38
39Below is a simple example of creating and running a CLI
40
41```go
42package main
43
44import (
45	"log"
46	"os"
47
48	"github.com/mitchellh/cli"
49)
50
51func main() {
52	c := cli.NewCLI("app", "1.0.0")
53	c.Args = os.Args[1:]
54	c.Commands = map[string]cli.CommandFactory{
55		"foo": fooCommandFactory,
56		"bar": barCommandFactory,
57	}
58
59	exitStatus, err := c.Run()
60	if err != nil {
61		log.Println(err)
62	}
63
64	os.Exit(exitStatus)
65}
66```
67
68