Debian Codegraph @

third_party/rust/clap/examples/tutorial_derive/03_04_subcommands.md

raw
1 ```console
2 $ 03_04_subcommands_derive help
3 A simple to use, efficient, and full-featured Command Line Argument Parser
4
5 Usage: 03_04_subcommands_derive[EXE] <COMMAND>
6
7 Commands:
8 add Adds files to myapp
9 help Print this message or the help of the given subcommand(s)
10
11 Options:
12 -h, --help Print help
13 -V, --version Print version
14
15 $ 03_04_subcommands_derive help add
16 Adds files to myapp
17
18 Usage: 03_04_subcommands_derive[EXE] add [NAME]
19
20 Arguments:
21 [NAME]
22
23 Options:
24 -h, --help Print help
25 -V, --version Print version
26
27 $ 03_04_subcommands_derive add bob
28 'myapp add' was used, name is: Some("bob")
29
30 ```
31
32 When specifying commands with `command: Commands`, they are required.
33 Alternatively, you could do `command: Option<Commands>` to make it optional.
34 ```console
35 $ 03_04_subcommands_derive
36 ? failed
37 A simple to use, efficient, and full-featured Command Line Argument Parser
38
39 Usage: 03_04_subcommands_derive[EXE] <COMMAND>
40
41 Commands:
42 add Adds files to myapp
43 help Print this message or the help of the given subcommand(s)
44
45 Options:
46 -h, --help Print help
47 -V, --version Print version
48
49 ```
50
51 Since we specified [`#[command(propagate_version = true)]`][crate::Command::propagate_version],
52 the `--version` flag is available in all subcommands:
53 ```console
54 $ 03_04_subcommands_derive --version
55 clap [..]
56
57 $ 03_04_subcommands_derive add --version
58 clap-add [..]
59
60 ```