|
184 | 184 | //! Err(err) => panic!("Invalid option: {}", err.option()),
|
185 | 185 | //! }
|
186 | 186 | //! ```
|
| 187 | +//! |
| 188 | +//! ## Parse for a OptStore struct |
| 189 | +//! |
| 190 | +//! The [Cmd] struct has the method parse_for which parses command line arguments and set their option values to |
| 191 | +//! the option store which is passed as an argument. |
| 192 | +//! |
| 193 | +//! This method divides command line arguments to command arguments and options, then sets each option value to a |
| 194 | +//! curresponding field of the option store. |
| 195 | +//! |
| 196 | +//! Within this method, a vector of [OptCfg] is made from the fields of the option store. This [OptCfg] vector is |
| 197 | +//! set to the public field cfgs of the [Cmd] instance. If you want to access this option configurations, get them |
| 198 | +//! from this field. |
| 199 | +//! An option configuration corresponding to each field of an option store is determined by its type and opt field |
| 200 | +//! attribute. |
| 201 | +//! If the type is bool, the option takes no argument. If the type is integer, floating point number or string, the |
| 202 | +//! option can takes single option argument, therefore it can appear once in command line arguments. |
| 203 | +//! If the type is a vector, the option can takes multiple option arguments, therefore it can appear multiple times |
| 204 | +//! in command line arguments. |
| 205 | +//! |
| 206 | +//! A `opt` field attribute can have the following pairs of name and value: one is `cfg` to specify `names` and |
| 207 | +//! `defaults` fields of [OptCfg] struct, another is `desc` to specify `desc` field, and yet another is `arg` to |
| 208 | +//! specify `arg_in_help` field. |
| 209 | +//! |
| 210 | +//! The format of `cfg` is like `cfg="f,foo=123"`. The left side of the equal sign is the option name(s), and the |
| 211 | +//! right side is the default value(s). |
| 212 | +//! If there is no equal sign, it is determined that only the option name is specified. |
| 213 | +//! If you want to specify multiple option names, separate them with commas. |
| 214 | +//! If you want to specify multiple default values, separate them with commas and round them with square brackets, |
| 215 | +//! like `[1,2,3]`. |
| 216 | +//! If you want to use your favorite carachter as a separator, you can use it by putting it on the left side of the |
| 217 | +//! open square bracket, like `/[1/2/3]`. |
| 218 | +//! |
| 219 | +//! NOTE: A default value of empty string array option in a field attribute is `[]`, like `#[opt(cfg="=[]")]`, but |
| 220 | +//! it doesn't represent an array which contains only one empty string. |
| 221 | +//! If you want to specify an array which contains only one emtpy string, write nothing after `=` symbol, like |
| 222 | +//! `#[opt(cfg="=")]`. |
187 | 223 |
|
188 | 224 | /// Enums for errors that can occur when parsing command line arguments.
|
189 | 225 | pub mod errors;
|
|
0 commit comments