mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
bfa02fd418
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"
1.1 KiB
1.1 KiB
Positional arguments are those values after the program name which are not preceded by any identifier (such as "myapp some_file"). Positionals support many of the same options as flags, as well as a few additional ones.
Let's look at their help:
$ 06_positional_args --help
MyApp
USAGE:
06_positional_args[EXE] <input> [config]
ARGS:
<input> the input file to use
<config> the config file to use
OPTIONS:
-h, --help Print help information
First, we see that the first argument is required:
$ 06_positional_args
? failed
error: The following required arguments were not provided:
<input>
<config>
USAGE:
06_positional_args[EXE] <input> [config]
For more information try --help
That first argument causes the second to be required:
$ 06_positional_args input.txt
? failed
error: The following required arguments were not provided:
<config>
USAGE:
06_positional_args[EXE] <input> <config> [config]
For more information try --help
Everything works now that we specify both:
$ 06_positional_args input.txt config.toml
An input file was specified
Doing work with input.txt and config.toml