Skip to content

Commit f32d640

Browse files
committed
docs(tutorial): Talk about required/optional subcommands
Inspired by #3342 Looks like we already cover this in the derive reference.
1 parent ea7699c commit f32d640

File tree

3 files changed

+43
-33
lines changed

3 files changed

+43
-33
lines changed

examples/tutorial_builder/03_04_subcommands.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ fn main() {
1717
"'myapp add' was used, name is: {:?}",
1818
sub_matches.value_of("NAME")
1919
),
20-
_ => unreachable!(),
20+
_ => unreachable!(
21+
"Exhausted list of subcommands and SubcommandRequiredElseHelp prevents `None`"
22+
),
2123
}
2224
}

examples/tutorial_builder/README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -272,22 +272,6 @@ subcommands.
272272

273273
[Example:](03_04_subcommands.rs)
274274
```console
275-
$ 03_04_subcommands
276-
? failed
277-
clap [..]
278-
A simple to use, efficient, and full-featured Command Line Argument Parser
279-
280-
USAGE:
281-
03_04_subcommands[EXE] <SUBCOMMAND>
282-
283-
OPTIONS:
284-
-h, --help Print help information
285-
-V, --version Print version information
286-
287-
SUBCOMMANDS:
288-
add Adds files to myapp
289-
help Print this message or the help of the given subcommand(s)
290-
291275
$ 03_04_subcommands help
292276
clap [..]
293277
A simple to use, efficient, and full-featured Command Line Argument Parser
@@ -322,6 +306,26 @@ $ 03_04_subcommands add bob
322306

323307
```
324308

309+
Because we set `AppSettings::SubcommandRequiredElseHelp`:
310+
```console
311+
$ 03_04_subcommands
312+
? failed
313+
clap [..]
314+
A simple to use, efficient, and full-featured Command Line Argument Parser
315+
316+
USAGE:
317+
03_04_subcommands[EXE] <SUBCOMMAND>
318+
319+
OPTIONS:
320+
-h, --help Print help information
321+
-V, --version Print version information
322+
323+
SUBCOMMANDS:
324+
add Adds files to myapp
325+
help Print this message or the help of the given subcommand(s)
326+
327+
```
328+
325329
Because we set `AppSettings::PropagateVersion`:
326330
```console
327331
$ 03_04_subcommands --version

examples/tutorial_derive/README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,22 +274,6 @@ subcommands.
274274

275275
[Example:](03_04_subcommands.rs)
276276
```console
277-
$ 03_04_subcommands_derive
278-
? failed
279-
clap [..]
280-
A simple to use, efficient, and full-featured Command Line Argument Parser
281-
282-
USAGE:
283-
03_04_subcommands_derive[EXE] <SUBCOMMAND>
284-
285-
OPTIONS:
286-
-h, --help Print help information
287-
-V, --version Print version information
288-
289-
SUBCOMMANDS:
290-
add Adds files to myapp
291-
help Print this message or the help of the given subcommand(s)
292-
293277
$ 03_04_subcommands_derive help
294278
clap [..]
295279
A simple to use, efficient, and full-featured Command Line Argument Parser
@@ -324,6 +308,26 @@ $ 03_04_subcommands_derive add bob
324308

325309
```
326310

311+
Because we used `command: Commands` instead of `command: Option<Commands>`:
312+
```console
313+
$ 03_04_subcommands_derive
314+
? failed
315+
clap [..]
316+
A simple to use, efficient, and full-featured Command Line Argument Parser
317+
318+
USAGE:
319+
03_04_subcommands_derive[EXE] <SUBCOMMAND>
320+
321+
OPTIONS:
322+
-h, --help Print help information
323+
-V, --version Print version information
324+
325+
SUBCOMMANDS:
326+
add Adds files to myapp
327+
help Print this message or the help of the given subcommand(s)
328+
329+
```
330+
327331
Because we set `AppSettings::PropagateVersion`:
328332
```console
329333
$ 03_04_subcommands_derive --version

0 commit comments

Comments
 (0)