2022-07-19 18:29:31 +00:00
|
|
|
```console
|
2022-08-08 19:05:08 +00:00
|
|
|
$ 03_04_subcommands_derive help
|
2022-07-19 18:29:31 +00:00
|
|
|
A simple to use, efficient, and full-featured Command Line Argument Parser
|
|
|
|
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: 03_04_subcommands_derive[EXE] <COMMAND>
|
2022-07-19 18:29:31 +00:00
|
|
|
|
2022-08-31 02:38:37 +00:00
|
|
|
Commands:
|
2022-09-07 20:29:15 +00:00
|
|
|
add Adds files to myapp
|
|
|
|
help Print this message or the help of the given subcommand(s)
|
2022-07-19 18:29:31 +00:00
|
|
|
|
2022-08-26 15:59:27 +00:00
|
|
|
Options:
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2022-08-26 15:59:27 +00:00
|
|
|
|
2022-08-08 19:05:08 +00:00
|
|
|
$ 03_04_subcommands_derive help add
|
2022-07-19 18:29:31 +00:00
|
|
|
Adds files to myapp
|
|
|
|
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: 03_04_subcommands_derive[EXE] add [NAME]
|
2022-07-19 18:29:31 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Arguments:
|
2022-09-07 20:29:15 +00:00
|
|
|
[NAME]
|
2022-07-19 18:29:31 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2022-07-19 18:29:31 +00:00
|
|
|
|
2022-08-08 19:05:08 +00:00
|
|
|
$ 03_04_subcommands_derive add bob
|
2022-07-19 18:29:31 +00:00
|
|
|
'myapp add' was used, name is: Some("bob")
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2023-09-12 01:50:12 +00:00
|
|
|
When specifying commands with `command: Commands`, they are required.
|
2023-09-14 03:56:05 +00:00
|
|
|
Alternatively, you could do `command: Option<Commands>` to make it optional.
|
2022-07-19 18:29:31 +00:00
|
|
|
```console
|
2022-08-08 19:05:08 +00:00
|
|
|
$ 03_04_subcommands_derive
|
2022-07-19 18:29:31 +00:00
|
|
|
? failed
|
|
|
|
A simple to use, efficient, and full-featured Command Line Argument Parser
|
|
|
|
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: 03_04_subcommands_derive[EXE] <COMMAND>
|
2022-07-19 18:29:31 +00:00
|
|
|
|
2022-08-31 02:38:37 +00:00
|
|
|
Commands:
|
2022-09-07 20:29:15 +00:00
|
|
|
add Adds files to myapp
|
|
|
|
help Print this message or the help of the given subcommand(s)
|
2022-07-19 18:29:31 +00:00
|
|
|
|
2022-08-26 15:59:27 +00:00
|
|
|
Options:
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2022-08-26 15:59:27 +00:00
|
|
|
|
2022-07-19 18:29:31 +00:00
|
|
|
```
|
|
|
|
|
2023-09-12 01:50:12 +00:00
|
|
|
Since we specified [`#[command(propagate_version = true)]`][crate::Command::propagate_version],
|
|
|
|
the `--version` flag is available in all subcommands:
|
2022-07-19 18:29:31 +00:00
|
|
|
```console
|
2022-08-08 19:05:08 +00:00
|
|
|
$ 03_04_subcommands_derive --version
|
2022-07-19 18:29:31 +00:00
|
|
|
clap [..]
|
|
|
|
|
2022-08-08 19:05:08 +00:00
|
|
|
$ 03_04_subcommands_derive add --version
|
2022-07-22 16:40:30 +00:00
|
|
|
clap-add [..]
|
2022-07-19 18:29:31 +00:00
|
|
|
|
|
|
|
```
|