|
55 | 55 | //! |
56 | 56 | #![doc = include_str!("../../examples/tutorial_derive/02_apps.md")] |
57 | 57 | //! |
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. |
59 | 59 | //! |
60 | 60 | //! ```rust |
61 | 61 | #![doc = include_str!("../../examples/tutorial_derive/02_crate.rs")] |
62 | 62 | //! ``` |
63 | 63 | #![doc = include_str!("../../examples/tutorial_derive/02_crate.md")] |
64 | 64 | //! |
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`]. |
66 | 66 | //! |
67 | 67 | //! ```rust |
68 | 68 | #![doc = include_str!("../../examples/tutorial_derive/02_app_settings.rs")] |
|
71 | 71 | //! |
72 | 72 | //! ## Adding Arguments |
73 | 73 | //! |
| 74 | +//! Arguments are inferred from the fields of your struct. |
| 75 | +//! |
74 | 76 | //! ### Positionals |
75 | 77 | //! |
76 | 78 | //! You can have users specify values by their position on the command-line: |
|
94 | 96 | //! - They can be optional |
95 | 97 | //! - Intent is clearer |
96 | 98 | //! |
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. |
100 | 102 | //! |
101 | 103 | //! ```rust |
102 | 104 | #![doc = include_str!("../../examples/tutorial_derive/03_02_option.rs")] |
|
128 | 130 | //! ``` |
129 | 131 | #![doc = include_str!("../../examples/tutorial_derive/03_01_flag_count.md")] |
130 | 132 | //! |
| 133 | +//! This also shows that any[`Arg`][crate::Args] method may be used as an attribute. |
| 134 | +//! |
131 | 135 | //! ### Subcommands |
132 | 136 | //! |
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. |
136 | 141 | //! |
137 | 142 | //! ```rust |
138 | 143 | #![doc = include_str!("../../examples/tutorial_derive/03_04_subcommands.rs")] |
|
165 | 170 | //! |
166 | 171 | //! For example, if you have arguments of specific values you want to test for, you can derive |
167 | 172 | //! [`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). |
169 | 174 | //! |
170 | 175 | //! This allows you specify the valid values for that argument. If the user does not use one of |
171 | 176 | //! those specific values, they will receive a graceful exit with error message informing them |
|
0 commit comments