clap is a Rust crate for defining and parsing command-line interfaces declaratively or imperatively. It generates help text, suggestions, colors, and shell completions for CLI tools.
Overview
clap lets Rust projects describe commands, flags, positional arguments, subcommands, and value parsers through a builder API or derive macros on structs. Parsed results land in a structured matches container for application logic. The crate aims for polished CLI behavior including common conventions, error formatting, and discoverable help output.
The project supports feature flags to trim dependencies, semver-style release pacing, and maintenance under the Rust WG-CLI umbrella. Ecosystem crates extend it with shell completions, man page generation, wildcard expansion on Windows, argfiles, internationalized errors, and Cargo.toml metadata integration.
Developers choose clap when they need flexible CLI layout without hand-rolling parsers, while accepting compile-time and binary-size trade-offs compared with minimal parsers. Documentation covers derive and builder tutorials, a cookbook, CLI concepts, and migration notes across major versions.
Key features
- Derive and builder APIs
- Subcommands and argument groups
- Help and version generation
- Shell completion support
- Colored error output
- Feature-flag modular builds
- Cargo.toml metadata macros
- Value parser type integration
Use cases
- Rust CLI application parsing
- Multi-subcommand developer tools
- Generated help and completions
- Structured flag validation
- Workspace-wide CLI consistency