mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +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.4 KiB
1.4 KiB
Subcommands function exactly like sub-Apps, because that's exactly what they are. Each instance of a Subcommand can have its own version, author(s), Args, and even its own subcommands.
Just like Apps, each subcommand will get its own "help" and "version" flags automatically generated. Also, like Apps, you can override "-V" or "-h" safely and still get "--help" and "--version" auto generated.
NOTE: If you specify a subcommand for your App, clap will also autogenerate a "help" subcommand along with "-h" and "--help" (applies to sub-subcommands as well).
$ 08_subcommands help
MyApp 1.0
USAGE:
08_subcommands[EXE] [SUBCOMMAND]
OPTIONS:
-h, --help Print help information
-V, --version Print version information
SUBCOMMANDS:
add Adds files to myapp
help Print this message or the help of the given subcommand(s)
$ 08_subcommands help add
08_subcommands[EXE]-add 0.1
Kevin K.
Adds files to myapp
USAGE:
08_subcommands[EXE] add <input>
ARGS:
<input> the file to add
OPTIONS:
-h, --help Print help information
-V, --version Print version information
$ 08_subcommands add help
'myapp add' was used, input is: help
$ 08_subcommands --version
MyApp 1.0
Without any subcommand:
$ 08_subcommands
No subcommand was used
And with:
$ 08_subcommands add input.txt
'myapp add' was used, input is: input.txt