• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

benches/H03-May-2022-2,0151,848

examples/H03-May-2022-3,5872,668

src/H03-May-2022-22,91212,287

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D01-Jan-197094 66

Cargo.lockH A D01-Jan-197025.1 KiB1,020908

Cargo.tomlH A D01-Jan-19709.4 KiB414334

Cargo.toml.orig-cargoH A D29-Nov-19738.8 KiB352290

LICENSE-APACHEH A D29-Nov-197311.1 KiB202169

LICENSE-MITH A D29-Nov-19731.1 KiB2217

README.mdH A D29-Nov-19737.8 KiB176129

README.md

1<!-- omit in TOC -->
2# clap
3
4> **Command Line Argument Parser for Rust**
5
6[![Crates.io](https://img.shields.io/crates/v/clap?style=flat-square)](https://crates.io/crates/clap)
7[![Crates.io](https://img.shields.io/crates/d/clap?style=flat-square)](https://crates.io/crates/clap)
8[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/v3.0.14/LICENSE-APACHE)
9[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/v3.0.14/LICENSE-MIT)
10[![Build Status](https://img.shields.io/github/workflow/status/clap-rs/clap/CI/staging?style=flat-square)](https://github.com/clap-rs/clap/actions/workflows/ci.yml?query=branch%3Astaging)
11[![Coverage Status](https://img.shields.io/coveralls/github/clap-rs/clap/master?style=flat-square)](https://coveralls.io/github/clap-rs/clap?branch=master)
12[![Contributors](https://img.shields.io/github/contributors/clap-rs/clap?style=flat-square)](https://github.com/clap-rs/clap/graphs/contributors)
13
14Dual-licensed under [Apache 2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT).
15
161. [About](#about)
172. Tutorial: [Builder API](https://github.com/clap-rs/clap/blob/v3.0.14/examples/tutorial_builder/README.md),  [Derive API](https://github.com/clap-rs/clap/blob/v3.0.14/examples/tutorial_derive/README.md)
183. [Examples](https://github.com/clap-rs/clap/blob/v3.0.14/examples/README.md)
194. [API Reference](https://docs.rs/clap)
20    - [Derive Reference](https://github.com/clap-rs/clap/blob/v3.0.14/examples/derive_ref/README.md)
21    - [Feature Flags](#feature-flags)
225. [CHANGELOG](https://github.com/clap-rs/clap/blob/v3.0.14/CHANGELOG.md)
236. [FAQ](https://github.com/clap-rs/clap/blob/v3.0.14/docs/FAQ.md)
247. [Questions & Discussions](https://github.com/clap-rs/clap/discussions)
258. [Contributing](https://github.com/clap-rs/clap/blob/v3.0.14/CONTRIBUTING.md)
268. [Sponsors](#sponsors)
27
28## About
29
30Create your command-line parser, with all of the bells and whistles, declaratively or procedurally.
31
32### Example
33
34This uses our
35[Derive API](https://github.com/clap-rs/clap/blob/v3.0.14/examples/tutorial_derive/README.md)
36which provides access to the [Builder API](https://github.com/clap-rs/clap/blob/v3.0.14/examples/tutorial_builder/README.md) as attributes on a `struct`:
37
38<!-- Copied from examples/demo.{rs,md} -->
39```rust,no_run
40use clap::Parser;
41
42/// Simple program to greet a person
43#[derive(Parser, Debug)]
44#[clap(author, version, about, long_about = None)]
45struct Args {
46    /// Name of the person to greet
47    #[clap(short, long)]
48    name: String,
49
50    /// Number of times to greet
51    #[clap(short, long, default_value_t = 1)]
52    count: u8,
53}
54
55fn main() {
56    let args = Args::parse();
57
58    for _ in 0..args.count {
59        println!("Hello {}!", args.name)
60    }
61}
62```
63Add this to `Cargo.toml`:
64```toml
65[dependencies]
66clap = { version = "3.0.14", features = ["derive"] }
67```
68```bash
69$ demo --help
70clap [..]
71Simple program to greet a person
72
73USAGE:
74    demo[EXE] [OPTIONS] --name <NAME>
75
76OPTIONS:
77    -c, --count <COUNT>    Number of times to greet [default: 1]
78    -h, --help             Print help information
79    -n, --name <NAME>      Name of the person to greet
80    -V, --version          Print version information
81```
82*(version number and `.exe` extension on windows replaced by placeholders)*
83
84### Aspirations
85
86- Out of the box, users get a polished CLI experience
87  - Including common argument behavior, help generation, suggested fixes for users, colored output, [shell completions](https://github.com/clap-rs/clap/tree/master/clap_complete), etc
88- Flexible enough to port your existing CLI interface
89  - However, we won't necessarily streamline support for each use case
90- Reasonable parse performance
91- Resilient maintainership, including
92  - Willing to break compatibility rather than batching up breaking changes in large releases
93  - Leverage feature flags to keep to one active branch
94  - Being under [WG-CLI](https://github.com/rust-cli/team/) to increase the bus factor
95- We follow semver and will wait about 6-9 months between major breaking changes
96- We will support the last two minor Rust releases (MSRV, currently 1.54.0)
97
98While these aspirations can be at odds with fast build times and low binary
99size, we will still strive to keep these reasonable for the flexibility you
100get.  Check out the
101[argparse-benchmarks](https://github.com/rust-cli/argparse-benchmarks-rs) for
102CLI parsers optimized for other use cases.
103
104### Selecting an API
105
106Why use the declarative [Derive API](https://github.com/clap-rs/clap/blob/v3.0.14/examples/tutorial_derive/README.md):
107- Easier to read, write, and modify
108- Easier to keep the argument declaration and reading of argument in sync
109- Easier to reuse, e.g. [clap-verbosity-flag](https://crates.io/crates/clap-verbosity-flag)
110
111Why use the procedural [Builder API](https://github.com/clap-rs/clap/blob/v3.0.14/examples/tutorial_builder/README.md):
112- Faster compile times if you aren't already using other procedural macros
113- More flexible, e.g. you can look up how many times an argument showed up,
114  what its values were, and what were the indexes of those values.  The Derive
115  API can only report presence, number of occurrences, or values but no indices
116  or combinations of data.
117
118### Related Projects
119
120- [wild](https://crates.io/crates/wild) for supporting wildcards (`*`) on Windows like you do Linux
121- [argfile](https://crates.io/crates/argfile) for loading additional arguments from a file (aka response files)
122- [clap_complete](https://crates.io/crates/clap_complete) for shell completion support
123- [clap-verbosity-flag](https://crates.io/crates/clap-verbosity-flag)
124- [clap-cargo](https://crates.io/crates/clap-cargo)
125- [concolor-clap](https://crates.io/crates/concolor-clap)
126- [Command-line Apps for Rust](https://rust-cli.github.io/book/index.html) book
127- [`trycmd`](https://crates.io/crates/trycmd):  Snapshot testing
128  - Or for more control, [`assert_cmd`](https://crates.io/crates/assert_cmd) and [`assert_fs`](https://crates.io/crates/assert_fs)
129
130## Feature Flags
131
132### Default Features
133
134* **std**: _Not Currently Used._ Placeholder for supporting `no_std` environments in a backwards compatible manner.
135* **color**: Turns on colored error messages.
136* **suggestions**: Turns on the `Did you mean '--myoption'?` feature for when users make typos.
137
138#### Optional features
139
140* **derive**: Enables the custom derive (i.e. `#[derive(Parser)]`). Without this you must use one of the other methods of creating a `clap` CLI listed above.
141* **cargo**: Turns on macros that read values from `CARGO_*` environment variables.
142* **env**: Turns on the usage of environment variables during parsing.
143* **regex**: Enables regex validators.
144* **unicode**: Turns on support for unicode characters (including emoji) in arguments and help messages.
145* **wrap_help**: Turns on the help text wrapping feature, based on the terminal size.
146
147#### Experimental features
148
149**Warning:** These may contain breaking changes between minor releases.
150
151* **unstable-replace**: Enable [`App::replace`](https://github.com/clap-rs/clap/issues/2836)
152* **unstable-multicall**: Enable [`AppSettings::Multicall`](https://github.com/clap-rs/clap/issues/2861)
153* **unstable-grouped**: Enable [`ArgMatches::grouped_values_of`](https://github.com/clap-rs/clap/issues/2924)
154
155## Sponsors
156
157<!-- omit in TOC -->
158### Gold
159
160[![](https://opencollective.com/clap/tiers/gold.svg?avatarHeight=36&width=600)](https://opencollective.com/clap)
161
162<!-- omit in TOC -->
163### Silver
164
165[![](https://opencollective.com/clap/tiers/silver.svg?avatarHeight=36&width=600)](https://opencollective.com/clap)
166
167<!-- omit in TOC -->
168### Bronze
169
170[![](https://opencollective.com/clap/tiers/bronze.svg?avatarHeight=36&width=600)](https://opencollective.com/clap)
171
172<!-- omit in TOC -->
173### Backer
174
175[![](https://opencollective.com/clap/tiers/backer.svg?avatarHeight=36&width=600)](https://opencollective.com/clap)
176