Favicon of CLI

CLI

urfave/cli is a Go library for building CLI apps with commands, flags, shell completion, and no external dependencies.

CLI website screenshot
CLI GitHub repository preview

urfave/cli is a Go library for building command line applications. It targets Go developers who want a declarative way to define commands, subcommands, and flags without pulling in extra dependencies beyond the Go standard library. The project has been around long enough to have a stable API, active maintenance, and companion modules for docs generation and structured config sources.

The library handles the repetitive parts of CLI building: parsing flags, generating help text, matching command aliases, and wiring up shell completion. You define your command tree declaratively (commands, subcommands, flags, actions) and the library takes care of parsing and dispatch.

Key features

  • Declarative API: define commands, subcommands, and flags as data structures rather than imperative parsing code.
  • Command and subcommand support: includes alias support and prefix matching, so users can type shortened command names.
  • Flexible help system: generates permissive, readable help output automatically from your command definitions.
  • Shell completion: dynamic completion scripts for bash, zsh, fish, and powershell.
  • No external dependencies: the core library relies only on the Go standard library.
  • Rich flag types: supports simple types, slices of simple types, time, and duration values as flags.
  • Compound short flags: lets users combine short flags like -a -b -c into -abc.
  • Documentation generation: man pages and Markdown docs are supported through the separate urfave/cli-docs module.
  • Configurable input sources: read flag values from environment variables, plain text files, or structured formats (JSON, TOML, YAML) via the urfave/cli-altsrc module.

Ideal use cases

This library fits developers writing internal tools, DevOps utilities, or public CLI products in Go where they want structured command handling instead of hand-rolling flag package logic. It works well for tools with nested subcommands (think git-style command trees) or apps that need shell completion out of the box.

It's also a good fit if you want config values to come from multiple sources (env vars, files, flags) without writing that merging logic yourself, since the urfave/cli-altsrc module handles JSON, TOML, and YAML sources.

It is not the right choice if you need a CLI framework for a language other than Go, or if your tool is a single command with one or two flags where the standard library's flag package is already sufficient. If you want a framework with a large ecosystem of third-party plugins, this library keeps its core dependency-free by design, so extra functionality lives in separate companion modules you add as needed.

Installation

Add the library to your Go module:

go get github.com/urfave/cli/v3

Import it in your code:

import "github.com/urfave/cli/v3"

Define a command and run it from your main function, using the command/flag structures documented on the hosted docs site. For documentation generation, add the companion module:

go get github.com/urfave/cli-docs

For loading flag values from structured config files (JSON, TOML, YAML) or environment variables beyond the built-in support, add:

go get github.com/urfave/cli-altsrc

Full usage examples, flag definitions, and API details live in the hosted documentation at cli.urfave.org, built from the repo's ./docs directory.

Frequently asked questions

Share:

Stars
24.3K
Forks
1.9K
Last commit
3 days ago
Repository age
13 years
License
MIT
Self-hosted
No
Activity score
82/100
View Repository
Built with:
Ad
Favicon

 

  
 

Similar to CLI

Favicon

 

  
 
Favicon

 

  
 
Favicon