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

..01-Sep-2019-

.github/H01-Sep-2019-15094

src/H01-Sep-2019-19,30210,860

.appveyor.ymlH A D01-Sep-2019478 1817

.cargo-checksum.jsonH A D01-Sep-20195 KiB11

.clog.tomlH A D01-Sep-2019324 1412

.mention-botH A D01-Sep-2019154 109

.travis.ymlH A D01-Sep-20191.7 KiB5958

CHANGELOG.mdH A D01-Sep-2019130.5 KiB2,6561,359

CONTRIBUTORS.mdH A D01-Sep-201920.2 KiB8862

Cargo.tomlH A D01-Sep-20192.6 KiB127108

LICENSE-MITH A D01-Sep-20191.1 KiB2217

README.mdH A D01-Sep-201933.6 KiB611461

SPONSORS.mdH A D01-Sep-2019392 75

clap-test.rsH A D01-Sep-20193.4 KiB7768

justfileH A D01-Sep-20191.1 KiB4031

rustfmt.tomlH A D01-Sep-201998 54

README.md

1clap
2====
3
4[![Crates.io](https://img.shields.io/crates/v/clap.svg)](https://crates.io/crates/clap) [![Crates.io](https://img.shields.io/crates/d/clap.svg)](https://crates.io/crates/clap) [![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/kbknapp/clap-rs/blob/master/LICENSE-MIT) [![Coverage Status](https://coveralls.io/repos/kbknapp/clap-rs/badge.svg?branch=master&service=github)](https://coveralls.io/github/kbknapp/clap-rs?branch=master) [![Join the chat at https://gitter.im/kbknapp/clap-rs](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/kbknapp/clap-rs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5
6Linux: [![Build Status](https://travis-ci.org/kbknapp/clap-rs.svg?branch=master)](https://travis-ci.org/kbknapp/clap-rs)
7Windows: [![Build status](https://ci.appveyor.com/api/projects/status/ejg8c33dn31nhv36/branch/master?svg=true)](https://ci.appveyor.com/project/kbknapp/clap-rs/branch/master)
8
9Command Line Argument Parser for Rust
10
11It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcommands when writing console/terminal applications.
12
13* [documentation](https://docs.rs/clap/)
14* [website](https://clap.rs/)
15* [video tutorials](https://www.youtube.com/playlist?list=PLza5oFLQGTl2Z5T8g1pRkIynR3E0_pc7U)
16
17Table of Contents
18=================
19
20* [What's New](#whats-new)
21* [About](#about)
22* [FAQ](#faq)
23* [Features](#features)
24* [Quick Example](#quick-example)
25* [Try it!](#try-it)
26  * [Pre-Built Test](#pre-built-test)
27  * [BYOB (Build Your Own Binary)](#byob-build-your-own-binary)
28* [Usage](#usage)
29  * [Optional Dependencies / Features](#optional-dependencies--features)
30  * [Dependencies Tree](#dependencies-tree)
31  * [More Information](#more-information)
32    * [Video Tutorials](#video-tutorials)
33* [How to Contribute](#how-to-contribute)
34  * [Compatibility Policy](#compatibility-policy)
35    * [Minimum Version of Rust](#minimum-version-of-rust)
36* [Related Crates](#related-crates)
37* [License](#license)
38* [Recent Breaking Changes](#recent-breaking-changes)
39  * [Deprecations](#deprecations)
40
41Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
42
43## What's New
44
45Here's whats new in 2.29.0:
46
47* **Arg:**  adds Arg::hide_env_values(bool) which allows one to hide any current env values and display only the key in help messages
48
49Here's whats new in 2.28.0:
50
51The minimum required Rust is now 1.20. This was done to start using bitflags 1.0 and having >1.0 deps is a *very good* thing!
52
53* Updates `bitflags` to 1.0
54* Adds the traits to be used with the `clap-derive` crate to be able to use Custom Derive (for now must be accessed with `unstable` feature flag)
55* Adds Arg::case_insensitive(bool) which allows matching Arg::possible_values without worrying about ASCII case
56* Fixes a regression where --help couldn't be overridden
57* adds '[SUBCOMMAND]' to usage strings with only AppSettings::AllowExternalSubcommands is used with no other subcommands
58* uses `.bash` for Bash completion scripts now instead of `.bash-completion` due to convention and `.bash-completion` not being supported by completion projects
59* Fix URL path to github hosted files
60* fix typos in docs
61* **README.md:**  updates the readme and pulls out some redundant sections
62* fixes a bug that allowed options to pass parsing when no value was provided
63* ignore PropagateGlobalValuesDown deprecation warning
64
65For full details, see [CHANGELOG.md](https://github.com/kbknapp/clap-rs/blob/master/CHANGELOG.md)
66
67## About
68
69`clap` is used to parse *and validate* the string of command line arguments provided by a user at runtime. You provide the list of valid possibilities, and `clap` handles the rest. This means you focus on your *applications* functionality, and less on the parsing and validating of arguments.
70
71`clap` provides many things 'for free' (with no configuration) including the traditional version and help switches (or flags) along with associated messages. If you are using subcommands, `clap` will also auto-generate a `help` subcommand and separate associated help messages.
72
73Once `clap` parses the user provided string of arguments, it returns the matches along with any applicable values. If the user made an error or typo, `clap` informs them with a friendly message and exits gracefully (or returns a `Result` type and allows you to perform any clean up prior to exit). Because of this, you can make reasonable assumptions in your code about the validity of the arguments prior to your applications main execution.
74
75## FAQ
76
77For a full FAQ and more in depth details, see [the wiki page](https://github.com/kbknapp/clap-rs/wiki/FAQ)
78
79### Comparisons
80
81First, let me say that these comparisons are highly subjective, and not meant in a critical or harsh manner. All the argument parsing libraries out there (to include `clap`) have their own strengths and weaknesses. Sometimes it just comes down to personal taste when all other factors are equal. When in doubt, try them all and pick one that you enjoy :) There's plenty of room in the Rust community for multiple implementations!
82
83#### How does `clap` compare to [getopts](https://github.com/rust-lang-nursery/getopts)?
84
85`getopts` is a very basic, fairly minimalist argument parsing library. This isn't a bad thing, sometimes you don't need tons of features, you just want to parse some simple arguments, and have some help text generated for you based on valid arguments you specify. The downside to this approach is that you must manually implement most of the common features (such as checking to display help messages, usage strings, etc.). If you want a highly custom argument parser, and don't mind writing the majority of the functionality yourself, `getopts` is an excellent base.
86
87`getopts` also doesn't allocate much, or at all. This gives it a very small performance boost. Although, as you start implementing additional features, that boost quickly disappears.
88
89Personally, I find many, many uses of `getopts` are manually implementing features that `clap` provides by default. Using `clap` simplifies your codebase allowing you to focus on your application, and not argument parsing.
90
91#### How does `clap` compare to [docopt.rs](https://github.com/docopt/docopt.rs)?
92
93I first want to say I'm a big a fan of BurntSushi's work, the creator of `Docopt.rs`. I aspire to produce the quality of libraries that this man does! When it comes to comparing these two libraries they are very different. `docopt` tasks you with writing a help message, and then it parsers that message for you to determine all valid arguments and their use. Some people LOVE this approach, others do not. If you're willing to write a detailed help message, it's nice that you can stick that in your program and have `docopt` do the rest. On the downside, it's far less flexible.
94
95`docopt` is also excellent at translating arguments into Rust types automatically. There is even a syntax extension which will do all this for you, if you're willing to use a nightly compiler (use of a stable compiler requires you to somewhat manually translate from arguments to Rust types). To use BurntSushi's words, `docopt` is also a sort of black box. You get what you get, and it's hard to tweak implementation or customize the experience for your use case.
96
97Because `docopt` is doing a ton of work to parse your help messages and determine what you were trying to communicate as valid arguments, it's also one of the more heavy weight parsers performance-wise. For most applications this isn't a concern and this isn't to say `docopt` is slow, in fact far from it. This is just something to keep in mind while comparing.
98
99#### All else being equal, what are some reasons to use `clap`? (The Pitch)
100
101`clap` is as fast, and as lightweight as possible while still giving all the features you'd expect from a modern argument parser. In fact, for the amount and type of features `clap` offers it remains about as fast as `getopts`. If you use `clap` when just need some simple arguments parsed, you'll find it's a walk in the park. `clap` also makes it possible to represent extremely complex, and advanced requirements, without too much thought. `clap` aims to be intuitive, easy to use, and fully capable for wide variety use cases and needs.
102
103#### All else being equal, what are some reasons *not* to use `clap`? (The Anti Pitch)
104
105Depending on the style in which you choose to define the valid arguments, `clap` can be very verbose. `clap` also offers so many finetuning knobs and dials, that learning everything can seem overwhelming. I strive to keep the simple cases simple, but when turning all those custom dials it can get complex. `clap` is also opinionated about parsing. Even though so much can be tweaked and tuned with `clap` (and I'm adding more all the time), there are still certain features which `clap` implements in specific ways which may be contrary to some users use-cases. Finally, `clap` is "stringly typed" when referring to arguments which can cause typos in code. This particular paper-cut is being actively worked on, and should be gone in v3.x.
106
107## Features
108
109Below are a few of the features which `clap` supports, full descriptions and usage can be found in the [documentation](https://docs.rs/clap/) and [examples/](examples) directory
110
111* **Auto-generated Help, Version, and Usage information**
112  - Can optionally be fully, or partially overridden if you want a custom help, version, or usage statements
113* **Auto-generated completion scripts at compile time (Bash, Zsh, Fish, and PowerShell)**
114  - Even works through many multiple levels of subcommands
115  - Works with options which only accept certain values
116  - Works with subcommand aliases
117* **Flags / Switches** (i.e. bool fields)
118  - Both short and long versions supported (i.e. `-f` and `--flag` respectively)
119  - Supports combining short versions (i.e. `-fBgoZ` is the same as `-f -B -g -o -Z`)
120  - Supports multiple occurrences (i.e. `-vvv` or `-v -v -v`)
121* **Positional Arguments** (i.e. those which are based off an index from the program name)
122  - Supports multiple values (i.e. `myprog <file>...` such as `myprog file1.txt file2.txt` being two values for the same "file" argument)
123  - Supports Specific Value Sets (See below)
124  - Can set value parameters (such as the minimum number of values, the maximum number of values, or the exact number of values)
125  - Can set custom validations on values to extend the argument parsing capability to truly custom domains
126* **Option Arguments** (i.e. those that take values)
127  - Both short and long versions supported (i.e. `-o value`, `-ovalue`, `-o=value` and `--option value` or `--option=value` respectively)
128  - Supports multiple values (i.e. `-o <val1> -o <val2>` or `-o <val1> <val2>`)
129  - Supports delimited values (i.e. `-o=val1,val2,val3`, can also change the delimiter)
130  - Supports Specific Value Sets (See below)
131  - Supports named values so that the usage/help info appears as `-o <FILE> <INTERFACE>` etc. for when you require specific multiple values
132  - Can set value parameters (such as the minimum number of values, the maximum number of values, or the exact number of values)
133  - Can set custom validations on values to extend the argument parsing capability to truly custom domains
134* **Sub-Commands** (i.e. `git add <file>` where `add` is a sub-command of `git`)
135  - Support their own sub-arguments, and sub-sub-commands independent of the parent
136  - Get their own auto-generated Help, Version, and Usage independent of parent
137* **Support for building CLIs from YAML** - This keeps your Rust source nice and tidy and makes supporting localized translation very simple!
138* **Requirement Rules**: Arguments can define the following types of requirement rules
139  - Can be required by default
140  - Can be required only if certain arguments are present
141  - Can require other arguments to be present
142  - Can be required only if certain values of other arguments are used
143* **Confliction Rules**: Arguments can optionally define the following types of exclusion rules
144  - Can be disallowed when certain arguments are present
145  - Can disallow use of other arguments when present
146* **Groups**: Arguments can be made part of a group
147  - Fully compatible with other relational rules (requirements, conflicts, and overrides) which allows things like requiring the use of any arg in a group, or denying the use of an entire group conditionally
148* **Specific Value Sets**: Positional or Option Arguments can define a specific set of allowed values (i.e. imagine a `--mode` option which may *only* have one of two values `fast` or `slow` such as `--mode fast` or `--mode slow`)
149* **Default Values**
150  - Also supports conditional default values (i.e. a default which only applies if specific arguments are used, or specific values of those arguments)
151* **Automatic Version from Cargo.toml**: `clap` is fully compatible with Rust's `env!()` macro for automatically setting the version of your application to the version in your Cargo.toml. See [09_auto_version example](examples/09_auto_version.rs) for how to do this (Thanks to [jhelwig](https://github.com/jhelwig) for pointing this out)
152* **Typed Values**: You can use several convenience macros provided by `clap` to get typed values (i.e. `i32`, `u8`, etc.) from positional or option arguments so long as the type you request implements `std::str::FromStr` See the [12_typed_values example](examples/12_typed_values.rs). You can also use `clap`s `arg_enum!` macro to create an enum with variants that automatically implement `std::str::FromStr`. See [13a_enum_values_automatic example](examples/13a_enum_values_automatic.rs) for details
153* **Suggestions**: Suggests corrections when the user enters a typo. For example, if you defined a `--myoption` argument, and the user mistakenly typed `--moyption` (notice `y` and `o` transposed), they would receive a `Did you mean '--myoption'?` error and exit gracefully. This also works for subcommands and flags. (Thanks to [Byron](https://github.com/Byron) for the implementation) (This feature can optionally be disabled, see 'Optional Dependencies / Features')
154* **Colorized Errors (Non Windows OS only)**: Error message are printed in in colored text (this feature can optionally be disabled, see 'Optional Dependencies / Features').
155* **Global Arguments**: Arguments can optionally be defined once, and be available to all child subcommands. There values will also be propagated up/down throughout all subcommands.
156* **Custom Validations**: You can define a function to use as a validator of argument values. Imagine defining a function to validate IP addresses, or fail parsing upon error. This means your application logic can be solely focused on *using* values.
157* **POSIX Compatible Conflicts/Overrides** - In POSIX args can be conflicting, but not fail parsing because whichever arg comes *last* "wins" so to speak. This allows things such as aliases (i.e. `alias ls='ls -l'` but then using `ls -C` in your terminal which ends up passing `ls -l -C` as the final arguments. Since `-l` and `-C` aren't compatible, this effectively runs `ls -C` in `clap` if you choose...`clap` also supports hard conflicts that fail parsing). (Thanks to [Vinatorul](https://github.com/Vinatorul)!)
158* Supports the Unix `--` meaning, only positional arguments follow
159
160## Quick Example
161
162The following examples show a quick example of some of the very basic functionality of `clap`. For more advanced usage, such as requirements, conflicts, groups, multiple values and occurrences see the [documentation](https://docs.rs/clap/), [examples/](examples) directory of this repository or the [video tutorials](https://www.youtube.com/playlist?list=PLza5oFLQGTl2Z5T8g1pRkIynR3E0_pc7U).
163
164 **NOTE:** All of these examples are functionally the same, but show different styles in which to use `clap`. These different styles are purely a matter of personal preference.
165
166The first example shows a method using the 'Builder Pattern' which allows more advanced configuration options (not shown in this small example), or even dynamically generating arguments when desired. The downside is it's more verbose.
167
168```rust
169// (Full example with detailed comments in examples/01b_quick_example.rs)
170//
171// This example demonstrates clap's full 'builder pattern' style of creating arguments which is
172// more verbose, but allows easier editing, and at times more advanced options, or the possibility
173// to generate arguments dynamically.
174extern crate clap;
175use clap::{Arg, App, SubCommand};
176
177fn main() {
178    let matches = App::new("My Super Program")
179                          .version("1.0")
180                          .author("Kevin K. <kbknapp@gmail.com>")
181                          .about("Does awesome things")
182                          .arg(Arg::with_name("config")
183                               .short("c")
184                               .long("config")
185                               .value_name("FILE")
186                               .help("Sets a custom config file")
187                               .takes_value(true))
188                          .arg(Arg::with_name("INPUT")
189                               .help("Sets the input file to use")
190                               .required(true)
191                               .index(1))
192                          .arg(Arg::with_name("v")
193                               .short("v")
194                               .multiple(true)
195                               .help("Sets the level of verbosity"))
196                          .subcommand(SubCommand::with_name("test")
197                                      .about("controls testing features")
198                                      .version("1.3")
199                                      .author("Someone E. <someone_else@other.com>")
200                                      .arg(Arg::with_name("debug")
201                                          .short("d")
202                                          .help("print debug information verbosely")))
203                          .get_matches();
204
205    // Gets a value for config if supplied by user, or defaults to "default.conf"
206    let config = matches.value_of("config").unwrap_or("default.conf");
207    println!("Value for config: {}", config);
208
209    // Calling .unwrap() is safe here because "INPUT" is required (if "INPUT" wasn't
210    // required we could have used an 'if let' to conditionally get the value)
211    println!("Using input file: {}", matches.value_of("INPUT").unwrap());
212
213    // Vary the output based on how many times the user used the "verbose" flag
214    // (i.e. 'myprog -v -v -v' or 'myprog -vvv' vs 'myprog -v'
215    match matches.occurrences_of("v") {
216        0 => println!("No verbose info"),
217        1 => println!("Some verbose info"),
218        2 => println!("Tons of verbose info"),
219        3 | _ => println!("Don't be crazy"),
220    }
221
222    // You can handle information about subcommands by requesting their matches by name
223    // (as below), requesting just the name used, or both at the same time
224    if let Some(matches) = matches.subcommand_matches("test") {
225        if matches.is_present("debug") {
226            println!("Printing debug info...");
227        } else {
228            println!("Printing normally...");
229        }
230    }
231
232    // more program logic goes here...
233}
234```
235
236The next example shows a far less verbose method, but sacrifices some of the advanced configuration options (not shown in this small example). This method also takes a *very* minor runtime penalty.
237
238```rust
239// (Full example with detailed comments in examples/01a_quick_example.rs)
240//
241// This example demonstrates clap's "usage strings" method of creating arguments
242// which is less verbose
243extern crate clap;
244use clap::{Arg, App, SubCommand};
245
246fn main() {
247    let matches = App::new("myapp")
248                          .version("1.0")
249                          .author("Kevin K. <kbknapp@gmail.com>")
250                          .about("Does awesome things")
251                          .args_from_usage(
252                              "-c, --config=[FILE] 'Sets a custom config file'
253                              <INPUT>              'Sets the input file to use'
254                              -v...                'Sets the level of verbosity'")
255                          .subcommand(SubCommand::with_name("test")
256                                      .about("controls testing features")
257                                      .version("1.3")
258                                      .author("Someone E. <someone_else@other.com>")
259                                      .arg_from_usage("-d, --debug 'Print debug information'"))
260                          .get_matches();
261
262    // Same as previous example...
263}
264```
265
266This third method shows how you can use a YAML file to build your CLI and keep your Rust source tidy
267or support multiple localized translations by having different YAML files for each localization.
268
269First, create the `cli.yml` file to hold your CLI options, but it could be called anything we like:
270
271```yaml
272name: myapp
273version: "1.0"
274author: Kevin K. <kbknapp@gmail.com>
275about: Does awesome things
276args:
277    - config:
278        short: c
279        long: config
280        value_name: FILE
281        help: Sets a custom config file
282        takes_value: true
283    - INPUT:
284        help: Sets the input file to use
285        required: true
286        index: 1
287    - verbose:
288        short: v
289        multiple: true
290        help: Sets the level of verbosity
291subcommands:
292    - test:
293        about: controls testing features
294        version: "1.3"
295        author: Someone E. <someone_else@other.com>
296        args:
297            - debug:
298                short: d
299                help: print debug information
300```
301
302Since this feature requires additional dependencies that not everyone may want, it is *not* compiled in by default and we need to enable a feature flag in Cargo.toml:
303
304Simply change your `clap = "2.29"` to `clap = {version = "2.87", features = ["yaml"]}`.
305
306Finally we create our `main.rs` file just like we would have with the previous two examples:
307
308```rust
309// (Full example with detailed comments in examples/17_yaml.rs)
310//
311// This example demonstrates clap's building from YAML style of creating arguments which is far
312// more clean, but takes a very small performance hit compared to the other two methods.
313#[macro_use]
314extern crate clap;
315use clap::App;
316
317fn main() {
318    // The YAML file is found relative to the current file, similar to how modules are found
319    let yaml = load_yaml!("cli.yml");
320    let matches = App::from_yaml(yaml).get_matches();
321
322    // Same as previous examples...
323}
324```
325
326Last but not least there is a macro version, which is like a hybrid approach offering the runtime speed of the builder pattern (the first example), but without all the verbosity.
327
328```rust
329#[macro_use]
330extern crate clap;
331
332fn main() {
333    let matches = clap_app!(myapp =>
334        (version: "1.0")
335        (author: "Kevin K. <kbknapp@gmail.com>")
336        (about: "Does awesome things")
337        (@arg CONFIG: -c --config +takes_value "Sets a custom config file")
338        (@arg INPUT: +required "Sets the input file to use")
339        (@arg debug: -d ... "Sets the level of debugging information")
340        (@subcommand test =>
341            (about: "controls testing features")
342            (version: "1.3")
343            (author: "Someone E. <someone_else@other.com>")
344            (@arg verbose: -v --verbose "Print test information verbosely")
345        )
346    ).get_matches();
347
348    // Same as before...
349}
350```
351
352If you were to compile any of the above programs and run them with the flag `--help` or `-h` (or `help` subcommand, since we defined `test` as a subcommand) the following would be output
353
354```sh
355$ myprog --help
356My Super Program 1.0
357Kevin K. <kbknapp@gmail.com>
358Does awesome things
359
360USAGE:
361    MyApp [FLAGS] [OPTIONS] <INPUT> [SUBCOMMAND]
362
363FLAGS:
364    -h, --help       Prints help information
365    -v               Sets the level of verbosity
366    -V, --version    Prints version information
367
368OPTIONS:
369    -c, --config <FILE>    Sets a custom config file
370
371ARGS:
372    INPUT    The input file to use
373
374SUBCOMMANDS:
375    help    Prints this message or the help of the given subcommand(s)
376    test    Controls testing features
377```
378
379**NOTE:** You could also run `myapp test --help` or `myapp help test` to see the help message for the `test` subcommand.
380
381## Try it!
382
383### Pre-Built Test
384
385To try out the pre-built examples, use the following steps:
386
387* Clone the repository `$ git clone https://github.com/kbknapp/clap-rs && cd clap-rs/`
388* Compile the example `$ cargo build --example <EXAMPLE>`
389* Run the help info `$ ./target/debug/examples/<EXAMPLE> --help`
390* Play with the arguments!
391* You can also do a onetime run via `$ cargo run --example <EXAMPLE> -- [args to example]
392
393### BYOB (Build Your Own Binary)
394
395To test out `clap`'s default auto-generated help/version follow these steps:
396* Create a new cargo project `$ cargo new fake --bin && cd fake`
397* Add `clap` to your `Cargo.toml`
398*
399```toml
400[dependencies]
401clap = "2"
402```
403
404* Add the following to your `src/main.rs`
405
406```rust
407extern crate clap;
408use clap::App;
409
410fn main() {
411  App::new("fake").version("v1.0-beta").get_matches();
412}
413```
414
415* Build your program `$ cargo build --release`
416* Run with help or version `$ ./target/release/fake --help` or `$ ./target/release/fake --version`
417
418## Usage
419
420For full usage, add `clap` as a dependency in your `Cargo.toml` () to use from crates.io:
421
422```toml
423[dependencies]
424clap = "~2.29"
425```
426
427(**note**: If you are concerned with supporting a minimum version of Rust that is *older* than the current stable Rust minus 2 stable releases, it's recommended to use the `~major.minor.patch` style versions in your `Cargo.toml` which will only update the patch version automatically. For more information see the [Compatibility Policy](#compatibility-policy))
428
429Then add `extern crate clap;` to your crate root.
430
431Define a list of valid arguments for your program (see the [documentation](https://docs.rs/clap/) or [examples/](examples) directory of this repo)
432
433Then run `cargo build` or `cargo update && cargo build` for your project.
434
435### Optional Dependencies / Features
436
437#### Features enabled by default
438
439* **"suggestions"**: Turns on the `Did you mean '--myoption'?` feature for when users make typos. (builds dependency `strsim`)
440* **"color"**: Turns on colored error messages. This feature only works on non-Windows OSs. (builds dependency `ansi-term`)
441* **"vec_map"**: Use [`VecMap`](https://crates.io/crates/vec_map) internally instead of a [`BTreeMap`](https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html). This feature provides a _slight_ performance improvement. (builds dependency `vec_map`)
442
443To disable these, add this to your `Cargo.toml`:
444
445```toml
446[dependencies.clap]
447version = "2.29"
448default-features = false
449```
450
451You can also selectively enable only the features you'd like to include, by adding:
452
453```toml
454[dependencies.clap]
455version = "2.29"
456default-features = false
457
458# Cherry-pick the features you'd like to use
459features = [ "suggestions", "color" ]
460```
461
462#### Opt-in features
463
464* **"yaml"**: Enables building CLIs from YAML documents. (builds dependency `yaml-rust`)
465* **"unstable"**: Enables unstable `clap` features that may change from release to release
466
467### Dependencies Tree
468
469The following graphic depicts `clap`s dependency graph (generated using [cargo-graph](https://github.com/kbknapp/cargo-graph)).
470
471 * **Dashed** Line: Optional dependency
472 * **Red** Color: **NOT** included by default (must use cargo `features` to enable)
473 * **Blue** Color: Dev dependency, only used while developing.
474
475![clap dependencies](clap_dep_graph.png)
476
477### More Information
478
479You can find complete documentation on the [docs.rs](https://docs.rs/clap/) for this project.
480
481You can also find usage examples in the [examples/](examples) directory of this repo.
482
483#### Video Tutorials
484
485There's also the video tutorial series [Argument Parsing with Rust v2](https://www.youtube.com/playlist?list=PLza5oFLQGTl2Z5T8g1pRkIynR3E0_pc7U).
486
487These videos slowly trickle out as I finish them and currently a work in progress.
488
489## How to Contribute
490
491Details on how to contribute can be found in the [CONTRIBUTING.md](.github/CONTRIBUTING.md) file.
492
493### Compatibility Policy
494
495Because `clap` takes SemVer and compatibility seriously, this is the official policy regarding breaking changes and minimum required versions of Rust.
496
497`clap` will pin the minimum required version of Rust to the CI builds. Bumping the minimum version of Rust is considered a minor breaking change, meaning *at a minimum* the minor version of `clap` will be bumped.
498
499In order to keep from being surprised of breaking changes, it is **highly** recommended to use the `~major.minor.patch` style in your `Cargo.toml` only if you wish to target a version of Rust that is *older* than current stable minus two releases:
500
501```toml
502[dependencies]
503clap = "~2.29"
504```
505
506This will cause *only* the patch version to be updated upon a `cargo update` call, and therefore cannot break due to new features, or bumped minimum versions of Rust.
507
508#### Warning about '~' Dependencies
509
510Using `~` can cause issues in certain circumstances.
511
512From @alexcrichton:
513
514Right now Cargo's version resolution is pretty naive, it's just a brute-force search of the solution space, returning the first resolvable graph. This also means that it currently won't terminate until it proves there is not possible resolvable graph. This leads to situations where workspaces with multiple binaries, for example, have two different dependencies such as:
515
516```toml,no_sync
517
518# In one Cargo.toml
519[dependencies]
520clap = "~2.29.0"
521
522# In another Cargo.toml
523[dependencies]
524clap = "2.29"
525```
526
527This is inherently an unresolvable crate graph in Cargo right now. Cargo requires there's only one major version of a crate, and being in the same workspace these two crates must share a version. This is impossible in this location, though, as these version constraints cannot be met.
528
529#### Minimum Version of Rust
530
531`clap` will officially support current stable Rust, minus two releases, but may work with prior releases as well. For example, current stable Rust at the time of this writing is 1.21.0, meaning `clap` is guaranteed to compile with 1.19.0 and beyond.
532
533At the 1.22.0 stable release, `clap` will be guaranteed to compile with 1.20.0 and beyond, etc.
534
535Upon bumping the minimum version of Rust (assuming it's within the stable-2 range), it *must* be clearly annotated in the `CHANGELOG.md`
536
537#### Breaking Changes
538
539`clap` takes a similar policy to Rust and will bump the major version number upon breaking changes with only the following exceptions:
540
541 * The breaking change is to fix a security concern
542 * The breaking change is to be fixing a bug (i.e. relying on a bug as a feature)
543 * The breaking change is a feature isn't used in the wild, or all users of said feature have given approval *prior* to the change
544
545## License
546
547`clap` is licensed under the MIT license. Please read the [LICENSE-MIT](LICENSE-MIT) file in this repository for more information.
548
549## Related Crates
550
551There are several excellent crates which can be used with `clap`, I recommend checking them all out! If you've got a crate that would be a good fit to be used with `clap` open an issue and let me know, I'd love to add it!
552
553* [`structopt`](https://github.com/TeXitoi/structopt) - This crate allows you to define a struct, and build a CLI from it! No more "stringly typed" and it uses `clap` behind the scenes! (*Note*: There is work underway to pull this crate into mainline `clap`).
554* [`assert_cli`](https://github.com/killercup/assert_cli) - This crate allows you test your CLIs in a very intuitive and functional way!
555
556## Recent Breaking Changes
557
558`clap` follows semantic versioning, so breaking changes should only happen upon major version bumps. The only exception to this rule is breaking changes that happen due to implementation that was deemed to be a bug, security concerns, or it can be reasonably proved to affect no code. For the full details, see [CHANGELOG.md](./CHANGELOG.md).
559
560As of 2.27.0:
561
562* Argument values now take precedence over subcommand names. This only arises by using unrestrained multiple values and subcommands together where the subcommand name can coincide with one of the multiple values. Such as `$ prog <files>... <subcommand>`. The fix is to place restraints on number of values, or disallow the use of `$ prog <prog-args> <subcommand>` structure.
563
564As of 2.0.0 (From 1.x)
565
566* **Fewer lifetimes! Yay!**
567 * `App<'a, 'b, 'c, 'd, 'e, 'f>` => `App<'a, 'b>`
568 * `Arg<'a, 'b, 'c, 'd, 'e, 'f>` => `Arg<'a, 'b>`
569 * `ArgMatches<'a, 'b>` => `ArgMatches<'a>`
570* **Simply Renamed**
571 * `App::arg_group` => `App::group`
572 * `App::arg_groups` => `App::groups`
573 * `ArgGroup::add` => `ArgGroup::arg`
574 * `ArgGroup::add_all` => `ArgGroup::args`
575 * `ClapError` => `Error`
576  * struct field `ClapError::error_type` => `Error::kind`
577 * `ClapResult` => `Result`
578 * `ClapErrorType` => `ErrorKind`
579* **Removed Deprecated Functions and Methods**
580 * `App::subcommands_negate_reqs`
581 * `App::subcommand_required`
582 * `App::arg_required_else_help`
583 * `App::global_version(bool)`
584 * `App::versionless_subcommands`
585 * `App::unified_help_messages`
586 * `App::wait_on_error`
587 * `App::subcommand_required_else_help`
588 * `SubCommand::new`
589 * `App::error_on_no_subcommand`
590 * `Arg::new`
591 * `Arg::mutually_excludes`
592 * `Arg::mutually_excludes_all`
593 * `Arg::mutually_overrides_with`
594 * `simple_enum!`
595* **Renamed Error Variants**
596 * `InvalidUnicode` => `InvalidUtf8`
597 * `InvalidArgument` => `UnknownArgument`
598* **Usage Parser**
599 * Value names can now be specified inline, i.e. `-o, --option <FILE> <FILE2> 'some option which takes two files'`
600 * **There is now a priority of order to determine the name** - This is perhaps the biggest breaking change. See the documentation for full details. Prior to this change, the value name took precedence. **Ensure your args are using the proper names (i.e. typically the long or short and NOT the value name) throughout the code**
601* `ArgMatches::values_of` returns an `Values` now which implements `Iterator` (should not break any code)
602* `crate_version!` returns `&'static str` instead of `String`
603
604### Deprecations
605
606Old method names will be left around for several minor version bumps, or one major version bump.
607
608As of 2.27.0:
609
610* **AppSettings::PropagateGlobalValuesDown:**  this setting deprecated and is no longer required to propagate values down or up
611