Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mitchellh/cli
A Go library for implementing command-line interfaces.
https://github.com/mitchellh/cli
Last synced: about 1 month ago
JSON representation
A Go library for implementing command-line interfaces.
- Host: GitHub
- URL: https://github.com/mitchellh/cli
- Owner: mitchellh
- License: mpl-2.0
- Archived: true
- Created: 2013-11-03T06:47:54.000Z (about 11 years ago)
- Default Branch: main
- Last Pushed: 2024-07-22T20:43:09.000Z (4 months ago)
- Last Synced: 2024-09-15T22:06:31.303Z (about 2 months ago)
- Language: Go
- Size: 178 KB
- Stars: 1,729
- Watchers: 25
- Forks: 122
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - mitchellh/cli - Go library for implementing command-line interfaces. (Command Line / Standard CLI)
- fucking-awesome-go - mitchellh/cli - Go library for implementing command-line interfaces. (Command Line / Standard CLI)
- awesome-go - mitchellh/cli - Go library for implementing command-line interfaces. (Command Line / Standard CLI)
- awesome-go - Go CLI - library for implementing command-line interfaces in Go. cli is the library that powers the CLI for Packer, Consul, Vault, Terraform, Nomad, and more. (CLI frameworks)
- awesome-go - mitchellh/cli - Go library for implementing command-line interfaces. Stars:`1.7K`. (Command Line / Standard CLI)
- awesome-go - mitchellh/cli - Go library for implementing command-line interfaces. (Command Line / Standard CLI)
- awesome-go - cli - A Go library for implementing command-line interfaces. - ★ 877 (Command Line)
- awesome-go-extra - cli - line interfaces.|1569|119|11|2013-11-03T06:47:54Z|2022-08-05T14:18:13Z| (Build Automation / Standard CLI)
- awesome-go-with-stars - mitchellh/cli - Go library for implementing command-line interfaces. (Command Line / Standard CLI)
- awesome-go-plus - mitchellh/cli - Go library for implementing command-line interfaces. (Command Line / Standard CLI)
- awesome-go-plus - mitchellh/cli - Go library for implementing command-line interfaces. (Command Line / Standard CLI)
README
🚨 This project is archived. 🚨 Learn More
# Go CLI Library [![GoDoc](https://godoc.org/github.com/mitchellh/cli?status.png)](https://pkg.go.dev/github.com/mitchellh/cli)
cli is a library for implementing command-line interfaces in Go.
cli is the library that powers the CLI for
[Packer](https://github.com/mitchellh/packer),
[Consul](https://github.com/hashicorp/consul),
[Vault](https://github.com/hashicorp/vault),
[Terraform](https://github.com/hashicorp/terraform),
[Nomad](https://github.com/hashicorp/nomad), and more.## Features
* Easy sub-command based CLIs: `cli foo`, `cli bar`, etc.
* Support for nested subcommands such as `cli foo bar`.
* Optional support for default subcommands so `cli` does something
other than error.* Support for shell autocompletion of subcommands, flags, and arguments
with callbacks in Go. You don't need to write any shell code.* Automatic help generation for listing subcommands.
* Automatic help flag recognition of `-h`, `--help`, etc.
* Automatic version flag recognition of `-v`, `--version`.
* Helpers for interacting with the terminal, such as outputting information,
asking for input, etc. These are optional, you can always interact with the
terminal however you choose.* Use of Go interfaces/types makes augmenting various parts of the library a
piece of cake.## Example
Below is a simple example of creating and running a CLI
```go
package mainimport (
"log"
"os""github.com/mitchellh/cli"
)func main() {
c := cli.NewCLI("app", "1.0.0")
c.Args = os.Args[1:]
c.Commands = map[string]cli.CommandFactory{
"foo": fooCommandFactory,
"bar": barCommandFactory,
}exitStatus, err := c.Run()
if err != nil {
log.Println(err)
}os.Exit(exitStatus)
}
```