Command Line Argument Parser for Rust
- Tutorial: Builder API, Derive API
- API Reference
- Questions & Discussions
Create your command-line parser, with all of the bells and whistles, declaratively or procedurally.
use Parser; /// Simple program to greet a person
(note: requires feature
(version number and
.exe extension on windows replaced by placeholders)
- Out of the box, users get a polished CLI experience
- Including common argument behavior, help generation, suggested fixes for users, colored output, shell completions, etc
- Flexible enough to port your existing CLI interface
- However, we won't necessarily streamline support for each use case
- Reasonable parse performance
- Resilient maintainership, including
- Willing to break compatibility rather than batching up breaking changes in large releases
- Leverage feature flags to keep to one active branch
- Being under WG-CLI to increase the bus factor
- We follow semver and will wait about 6-9 months between major breaking changes
- We will support the last two minor Rust releases (MSRV, currently 1.54.0)
While these aspirations can be at odds with fast build times and low binary size, we will still strive to keep these reasonable for the flexibility you get. Check out the argparse-benchmarks for CLI parsers optimized for other use cases.
- Command-line Apps for Rust book
trycmd: Snapshot testing
- std: Not Currently Used. Placeholder for supporting
no_stdenvironments in a backwards compatible manner.
- color: Turns on colored error messages.
- suggestions: Turns on the
Did you mean '--myoption'?feature for when users make typos.
- derive: Enables the custom derive (i.e.
#[derive(Parser)]). Without this you must use one of the other methods of creating a
clapCLI listed above.
- cargo: Turns on macros that read values from
- env: Turns on the usage of environment variables during parsing.
- regex: Enables regex validators.
- unicode: Turns on support for unicode characters (including emoji) in arguments and help messages.
- wrap_help: Turns on the help text wrapping feature, based on the terminal size.
Warning: These may contain breaking changes between minor releases.
- unstable-replace: Enable
- unstable-multicall: Enable
- unstable-grouped: Enable