| tag | ebe0f01a80ec8a27de232eb838e74fe9d7101240 | |
|---|---|---|
| tagger | Ed Page <eopage@gmail.com> | Wed Feb 23 15:40:15 2022 |
| object | 20dc6673bccbb29c353ef7a908f0bdbbdbc8a898 |
v3.1.2
| commit | 20dc6673bccbb29c353ef7a908f0bdbbdbc8a898 | [log] [tgz] |
|---|---|---|
| author | Ed Page <eopage@gmail.com> | Wed Feb 23 15:39:40 2022 |
| committer | Ed Page <eopage@gmail.com> | Wed Feb 23 15:39:40 2022 |
| tree | db2bbca0b64a5f784ec56deba0eaa831279925b8 | |
| parent | 2f9cae8cb4d812112611334d2a91d349e4402e4e [diff] |
chore: Release
Command Line Argument Parser for Rust
Dual-licensed under Apache 2.0 or MIT.
Create your command-line parser, with all of the bells and whistles, declaratively or procedurally.
This uses our Derive API which provides access to the Builder API as attributes on a struct:
use clap::Parser; /// Simple program to greet a person #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] struct Args { /// Name of the person to greet #[clap(short, long)] name: String, /// Number of times to greet #[clap(short, long, default_value_t = 1)] count: u8, } fn main() { let args = Args::parse(); for _ in 0..args.count { println!("Hello {}!", args.name) } }
Add this to Cargo.toml:
[dependencies] clap = { version = "3.1.2", features = ["derive"] }
$ demo --help clap [..] Simple program to greet a person USAGE: demo[EXE] [OPTIONS] --name <NAME> OPTIONS: -c, --count <COUNT> Number of times to greet [default: 1] -h, --help Print help information -n, --name <NAME> Name of the person to greet -V, --version Print version information
(version number and .exe extension on windows replaced by placeholders)
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.
Why use the declarative Derive API:
Why use the procedural Builder API:
*) on Windows like you do LinuxCommand::long_versiontrycmd: Snapshot testingassert_cmd and assert_fsno_std environments in a backwards compatible manner.Did you mean '--myoption'? feature for when users make typos.#[derive(Parser)]). Without this you must use one of the other methods of creating a clap CLI listed above.CARGO_* environment variables.Warning: These may contain breaking changes between minor releases.
Command::replaceCommand::multicallArgMatches::grouped_values_of