No description
  • Go 99.2%
  • Makefile 0.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-06-12 10:20:03 +01:00
.github ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
.go-version build: Update Go version and moderinize CI setup. (#15) 2026-06-05 16:26:21 +01:00
.golangci.yaml ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
autocomplete.go [COMPLIANCE] Update Copyright and License Headers (#13) 2025-11-02 18:10:26 +05:30
CHANGELOG.md chore: add CHANGELOG.md to track project changes (#10) 2025-05-29 21:31:29 +05:30
cli.go ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
cli_test.go ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
command.go [COMPLIANCE] Update Copyright and License Headers (#13) 2025-11-02 18:10:26 +05:30
command_mock.go [COMPLIANCE] Update Copyright and License Headers (#13) 2025-11-02 18:10:26 +05:30
command_mock_test.go [COMPLIANCE] Update Copyright and License Headers (#13) 2025-11-02 18:10:26 +05:30
go.mod Coverage test (#7) 2025-03-17 18:15:44 +05:30
go.sum IND-1807 Vulnerability fix (#6) 2025-01-29 15:11:21 +05:30
help.go ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
LICENSE ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
Makefile ci: Fix incorrect dep path and echo in makefile. (#17) 2026-06-12 10:20:03 +01:00
README.md s/mitchellh/hashicorp/g 2023-11-20 13:03:34 -08:00
ui.go ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
ui_colored.go ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
ui_common.go ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
ui_concurrent.go [COMPLIANCE] Update Copyright and License Headers (#13) 2025-11-02 18:10:26 +05:30
ui_concurrent_test.go [COMPLIANCE] Update Copyright and License Headers (#13) 2025-11-02 18:10:26 +05:30
ui_js.go [COMPLIANCE] Update Copyright and License Headers (#13) 2025-11-02 18:10:26 +05:30
ui_mock.go ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
ui_mock_test.go ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
ui_test.go ci: Create and enable copywrite header workflow. (#16) 2026-06-09 12:50:16 +01:00
ui_writer.go [COMPLIANCE] Update Copyright and License Headers (#13) 2025-11-02 18:10:26 +05:30
ui_writer_test.go [COMPLIANCE] Update Copyright and License Headers (#13) 2025-11-02 18:10:26 +05:30

Go CLI Library GoDoc

cli is a library for implementing command-line interfaces in Go. cli is the library that powers the CLI for Packer, Consul, Vault, Terraform, 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

package main

import (
	"log"
	"os"

	"github.com/hashicorp/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)
}