File tree Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,10 @@ $ 03_04_subcommands add bob
2929
3030```
3131
32- Because we set [ ` Command::arg_required_else_help ` ] [ crate::Command::arg_required_else_help ] :
32+ We set
33+ [ ` Command::arg_required_else_help ` ] [ crate::Command::arg_required_else_help ] to
34+ show the help, rather than an error, when the
35+ [ required subcommand] [ crate::Command::subcommand_required ] is missing:
3336``` console
3437$ 03_04_subcommands
3538? failed
Original file line number Diff line number Diff line change @@ -29,8 +29,8 @@ $ 03_04_subcommands_derive add bob
2929
3030```
3131
32- When specifying commands with ` command: Commands ` , they are required.
33- Alternatively, you could do ` command: Option<Commands> ` to make it optional .
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 ] .
3434``` console
3535$ 03_04_subcommands_derive
3636? failed
@@ -47,6 +47,7 @@ Options:
4747 -V, --version Print version
4848
4949```
50+ To make a subcommand optional, wrap it in an ` Option ` (e.g. ` command: Option<Commands> ` ).
5051
5152Since we specified [ ` #[command(propagate_version = true)] ` ] [ crate::Command::propagate_version ] ,
5253the ` --version ` flag is available in all subcommands:
Original file line number Diff line number Diff line change 88//! 3. [Arg Attributes](#arg-attributes)
99//! 4. [ValueEnum Attributes](#valueenum-attributes)
1010//! 5. [Possible Value Attributes](#possible-value-attributes)
11- //! 3. [Arg Types](#arg -types)
11+ //! 3. [Field Types](#field -types)
1212//! 4. [Doc Comments](#doc-comments)
1313//! 5. [Mixing Builder and Derive APIs](#mixing-builder-and-derive-apis)
1414//! 6. [Tips](#tips)
294294//! - When not present: [Doc comment summary](#doc-comments)
295295//! - `skip`: Ignore this variant
296296//!
297- //! ## Arg Types
297+ //! ## Field Types
298298//!
299- //! `clap` assumes some intent based on the type used:
299+ //! `clap` assumes some intent based on the type used.
300+ //!
301+ //! ### Subcommand Types
302+ //!
303+ //! | Type | Effect | Implies |
304+ //! |-----------------------|---------------------|-----------------------------------------------------------|
305+ //! | `Option<T>` | optional subcommand | |
306+ //! | `T` | required subcommand | `.subcommand_required(true).arg_required_else_help(true)` |
307+ //!
308+ //! ### Arg Types
300309//!
301310//! | Type | Effect | Implies | Notes |
302311//! |-----------------------|------------------------------------------------------|-------------------------------------------------------------|-------|
You can’t perform that action at this time.
0 commit comments