mirror of
https://github.com/clap-rs/clap
synced 2025-03-05 07:47:40 +00:00
This ports our example testing over to [trycmd](https://docs.rs/) so we can: - More thoroughly test our examples - Provide always-up-to-date example usage The old way of testing automatically picked up examples. This new way requires we have a `.md` file that uses the example in some way. Notes: - Moved overall example description to the `.md` file - I added cross-linking between related examples - `14_groups` had a redundant paragraph (twice talked about "one and only one"
30 lines
748 B
Markdown
30 lines
748 B
Markdown
Using `Arg::default_value`, rather than `Option::unwrap_or`, gives clap more information it can use with our argument.
|
|
|
|
For example, let's look at the help:
|
|
```bash
|
|
$ 10_default_values --help
|
|
myapp
|
|
|
|
does awesome things
|
|
|
|
USAGE:
|
|
10_default_values[EXE] [OPTIONS] [INPUT]
|
|
|
|
ARGS:
|
|
<INPUT> The input file to use [default: input.txt]
|
|
|
|
OPTIONS:
|
|
-c <CONFIG> The config file to use
|
|
-h, --help Print help information
|
|
```
|
|
`<INPUT>`'s description says what the default is while `-c`'s does not.
|
|
|
|
Otherwise, they'll work the same:
|
|
```bash
|
|
$ 10_default_values
|
|
The input file is: input.txt
|
|
The config file is: config.json
|
|
$ 10_default_values other.txt -c other.toml
|
|
The input file is: other.txt
|
|
The config file is: other.toml
|
|
```
|