click-rs
A Rust port of Python's Click library for creating beautiful command-line interfaces in a composable, declarative way.
click-rs lets you build CLIs from commands, groups, options and arguments, with automatic help generation, prompts, colored output, shell completion, and a testing harness, using either a derive macro or a builder API.
Attribution. click-rs is a derivative work: a Rust port of the excellent Click library by the Pallets team. All credit for the original design and API goes to them. This project aims to bring that ergonomics to the Rust ecosystem.
Compatibility
Works on Linux, macOS, and Windows.
Minimum Supported Rust Version: 1.70+
Installing
The crate is published as click-rs, but its library is imported as click:
[]
= "1.0"
use Command;
The derive feature is enabled by default. Disable it with default-features = false to use
the builder API only.
Quick Start (derive)
use Command;
/// A friendly greeter
Features
- Commands & groups: compose nested subcommands with shared context
- Options & arguments: typed parameters with defaults, flags, multiple values
- Automatic help: generated usage and
--helpoutput - Prompts & I/O: interactive prompts, confirmation, and piped input/output
- Colored output: styled terminal text
- Shell completion: generate completion scripts
- Validation: custom parameter validation and error reporting
- Testing: a
CliRunnerharness for invoking commands in tests
Examples
The examples/ directory mirrors classic Click examples:
| Example | Shows |
|---|---|
naval |
The canonical Click "naval fate" multi-command app |
repo |
Groups, context objects, and shared state |
complex |
Plugin-style command loading |
aliases |
Command aliases |
colors |
Colored terminal output |
completion |
Shell completion generation |
validation |
Custom parameter validation |
inout |
Reading from and writing to files / stdin / stdout |
imagepipe |
Piping data between commands |
termui |
Terminal UI helpers (prompts, progress) |
Run one with:
License
Licensed under the MIT License.