Skip to content

Commit a7cf4e9

Browse files
sphynxTeXitoi
authored andcommitted
Docs: tell about possible literals use for attribute values (#195)
1 parent 18d8aae commit a7cf4e9

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

src/lib.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@
8585
//! - `author`: Defaults to the crate author name given by Cargo.
8686
//! - `about`: Defaults to the crate description given by Cargo.
8787
//!
88-
//! Methods from `clap::App` that don't take an `&str` can be called by
89-
//! wrapping them in `raw()`, e.g. to activate colored help text:
88+
//! This approach also works for booleans and numbers which can be
89+
//! used as values of the attributes for corresponding `clap::App`
90+
//! methods (e.g. for `fn function(self, bool)` and so on).
91+
//!
92+
//! Methods from `clap::App` that don't take an atomic literal
93+
//! argument (`&str`, `bool` or numbers) can be called by wrapping
94+
//! them in `raw()`, e.g. to activate colored help text:
9095
//!
9196
//! ```
9297
//! #[macro_use]
@@ -105,14 +110,17 @@
105110
//! # fn main() {}
106111
//! ```
107112
//!
108-
//! Then, each field of the struct not marked as a subcommand corresponds
109-
//! to a `clap::Arg`. As with the struct attributes, every method of
110-
//! `clap::Arg` in the form of `fn function_name(self, &str)` can be used
111-
//! through specifying it as an attribute. The `name` attribute can be used
112-
//! to customize the `Arg::with_name()` call (defaults to the field name in
113-
//! kebab-case).
114-
//! For functions that do not take a `&str` as argument, the attribute can be
115-
//! wrapped in `raw()`, e. g. `raw(aliases = r#"&["alias"]"#, next_line_help = "true")`.
113+
//! Then, each field of the struct not marked as a subcommand
114+
//! corresponds to a `clap::Arg`. As with the struct attributes, every
115+
//! method of `clap::Arg` in the form of `fn function_name(self,
116+
//! &str)`, `fn function_name(self, bool)` or `fn function_name(self,
117+
//! usize)` can be used through specifying it as an attribute with a
118+
//! literal value. The `name` attribute can be used to customize the
119+
//! `Arg::with_name()` call (defaults to the field name in
120+
//! kebab-case). For functions that do not take an atomic literal as
121+
//! argument, the attribute can be wrapped in `raw()`, e. g.
122+
//! `raw(aliases = r#"&["alias"]"#, possible_values = r#"&["fast",
123+
//! "slow"]"#)`.
116124
//!
117125
//! The type of the field gives the kind of argument:
118126
//!

0 commit comments

Comments
 (0)