Skip to content

Commit

Permalink
Merge pull request #3343 from epage/sub
Browse files Browse the repository at this point in the history
docs(tutorial): Talk about required/optional subcommands
  • Loading branch information
epage authored Jan 25, 2022
2 parents ea7699c + f32d640 commit b88faad
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
4 changes: 3 additions & 1 deletion examples/tutorial_builder/03_04_subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ fn main() {
"'myapp add' was used, name is: {:?}",
sub_matches.value_of("NAME")
),
_ => unreachable!(),
_ => unreachable!(
"Exhausted list of subcommands and SubcommandRequiredElseHelp prevents `None`"
),
}
}
36 changes: 20 additions & 16 deletions examples/tutorial_builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,6 @@ subcommands.

[Example:](03_04_subcommands.rs)
```console
$ 03_04_subcommands
? failed
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
03_04_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)

$ 03_04_subcommands help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser
Expand Down Expand Up @@ -322,6 +306,26 @@ $ 03_04_subcommands add bob

```

Because we set `AppSettings::SubcommandRequiredElseHelp`:
```console
$ 03_04_subcommands
? failed
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
03_04_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)

```

Because we set `AppSettings::PropagateVersion`:
```console
$ 03_04_subcommands --version
Expand Down
36 changes: 20 additions & 16 deletions examples/tutorial_derive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,22 +274,6 @@ subcommands.

[Example:](03_04_subcommands.rs)
```console
$ 03_04_subcommands_derive
? failed
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
03_04_subcommands_derive[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)

$ 03_04_subcommands_derive help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser
Expand Down Expand Up @@ -324,6 +308,26 @@ $ 03_04_subcommands_derive add bob

```

Because we used `command: Commands` instead of `command: Option<Commands>`:
```console
$ 03_04_subcommands_derive
? failed
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
03_04_subcommands_derive[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)

```

Because we set `AppSettings::PropagateVersion`:
```console
$ 03_04_subcommands_derive --version
Expand Down

0 comments on commit b88faad

Please sign in to comment.