| 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][crate::Command::subcommand_required]. |
| 33 | By default, a missing subcommand will [show help rather than error][crate::Command::arg_required_else_help]. |
| 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 | To make a subcommand optional, wrap it in an `Option` (e.g. `command: Option<Commands>`). |
| 51 | |
| 52 | Since we specified [`#[command(propagate_version = true)]`][crate::Command::propagate_version], |
| 53 | the `--version` flag is available in all subcommands: |
| 54 | ```console |
| 55 | $ 03_04_subcommands_derive --version |
| 56 | clap [..] |
| 57 | |
| 58 | $ 03_04_subcommands_derive add --version |
| 59 | clap-add [..] |
| 60 | |
| 61 | ``` |