Skip to content

Commit 20987de

Browse files
authored
Merge pull request #5121 from epage/docs
docs(tutorial): Try to clean up the text
2 parents 37ba607 + 9e7404b commit 20987de

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

examples/tutorial_builder/03_04_subcommands.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ Options:
4747

4848
```
4949

50-
Because we set [`Command::propagate_version`][crate::Command::propagate_version]:
50+
Since we specified [`Command::propagate_version`][crate::Command::propagate_version], the `--version` flag
51+
is available in all subcommands:
5152
```console
5253
$ 03_04_subcommands --version
5354
clap [..]

examples/tutorial_derive/03_04_subcommands.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ $ 03_04_subcommands_derive add bob
2929

3030
```
3131

32-
Because we used `command: Commands` instead of `command: Option<Commands>`:
32+
When specifying commands with `command: Commands`, they are required.
33+
Alternatively, you could do `commaand: Option<Commands>` to make it optional.
3334
```console
3435
$ 03_04_subcommands_derive
3536
? failed
@@ -47,7 +48,8 @@ Options:
4748

4849
```
4950

50-
Because we added `#[command(propagate_version = true)]`:
51+
Since we specified [`#[command(propagate_version = true)]`][crate::Command::propagate_version],
52+
the `--version` flag is available in all subcommands:
5153
```console
5254
$ 03_04_subcommands_derive --version
5355
clap [..]

src/_derive/_tutorial.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@
5555
//!
5656
#![doc = include_str!("../../examples/tutorial_derive/02_apps.md")]
5757
//!
58-
//! You can use [`#[command(author, version, about)]` attribute defaults][super#command-attributes] to fill these fields in from your `Cargo.toml` file.
58+
//! You can use [`#[command(author, version, about)]` attribute defaults][super#command-attributes] on the struct to fill these fields in from your `Cargo.toml` file.
5959
//!
6060
//! ```rust
6161
#![doc = include_str!("../../examples/tutorial_derive/02_crate.rs")]
6262
//! ```
6363
#![doc = include_str!("../../examples/tutorial_derive/02_crate.md")]
6464
//!
65-
//! You can use attributes to change the application level behavior of clap. Any [`Command`][crate::Command] builder function can be used as an attribute, like [`Command::next_line_help`].
65+
//! You can use `#[command]` attributes on the struct to change the application level behavior of clap. Any [`Command`][crate::Command] builder function can be used as an attribute, like [`Command::next_line_help`].
6666
//!
6767
//! ```rust
6868
#![doc = include_str!("../../examples/tutorial_derive/02_app_settings.rs")]
@@ -71,6 +71,8 @@
7171
//!
7272
//! ## Adding Arguments
7373
//!
74+
//! Arguments are inferred from the fields of your struct.
75+
//!
7476
//! ### Positionals
7577
//!
7678
//! You can have users specify values by their position on the command-line:
@@ -94,9 +96,9 @@
9496
//! - They can be optional
9597
//! - Intent is clearer
9698
//!
97-
//! The [`#[arg(short = 'n')]`][Arg::short] and [`#[arg(long = "name")]`][Arg::long] attributes that define
98-
//! the flags are [`Arg`][crate::Args] methods that are derived from the field name when no value
99-
//! is specified ([`#[arg(short)]` and `#[arg(long)]`][super#arg-attributes]).
99+
//! To specify the flags for an argument, you can use [`#[arg(short = 'n')]`][Arg::short] and/or
100+
//! [`#[arg(long = "name")]`][Arg::long] attributes on a field. When no value is given (e.g.
101+
//! `#[arg(short)]`), the flag is inferred from the field's name.
100102
//!
101103
//! ```rust
102104
#![doc = include_str!("../../examples/tutorial_derive/03_02_option.rs")]
@@ -128,11 +130,14 @@
128130
//! ```
129131
#![doc = include_str!("../../examples/tutorial_derive/03_01_flag_count.md")]
130132
//!
133+
//! This also shows that any[`Arg`][crate::Args] method may be used as an attribute.
134+
//!
131135
//! ### Subcommands
132136
//!
133-
//! Subcommands are derived with `#[derive(Subcommand)]` and be added via [`#[command(subcommand)]` attribute][super#command-attributes]. Each
134-
//! instance of a [Subcommand][crate::Subcommand] can have its own version, author(s), Args, and even its own
135-
//! subcommands.
137+
//! Subcommands are derived with `#[derive(Subcommand)]` and be added via
138+
//! [`#[command(subcommand)]` attribute][super#command-attributes] on the field using that type.
139+
//! Each instance of a [Subcommand][crate::Subcommand] can have its own version, author(s), Args,
140+
//! and even its own subcommands.
136141
//!
137142
//! ```rust
138143
#![doc = include_str!("../../examples/tutorial_derive/03_04_subcommands.rs")]
@@ -165,7 +170,7 @@
165170
//!
166171
//! For example, if you have arguments of specific values you want to test for, you can derive
167172
//! [`ValueEnum`][super#valueenum-attributes]
168-
//! (any [`PossibleValue`] builder function can be used as variant attributes).
173+
//! (any [`PossibleValue`] builder function can be used as a `#[value]` attribute on enum variants).
169174
//!
170175
//! This allows you specify the valid values for that argument. If the user does not use one of
171176
//! those specific values, they will receive a graceful exit with error message informing them

0 commit comments

Comments
 (0)