Skip to content

Commit 57498ee

Browse files
committed
doc,comment: modified README and document comments (#28)
1 parent d01cd09 commit 57498ee

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ If you want to prioritize the output of short option name first in the help text
120120
This crate provides the validator `cliargs::validators::validate_number<T>` which validates whether an option argument is valid format as a number.
121121

122122
The ownership of the vector of option configurations which is passed as an argument of this method
123-
is moved to this method and set to the public field `cfgs` of [Cmd] instance.
123+
is moved to this method and set to the public field `cfgs` of `Cmd` instance.
124124
If you want to access the option configurations after parsing, get them from this field.
125125

126126
```
@@ -166,7 +166,7 @@ This method divides command line arguments to command arguments and options, the
166166
each option value to a curresponding field of the option store.
167167

168168
Within this method, a vector of `OptCfg` is made from the fields of the option store.
169-
This [OptCfg] vector is set to the public field `cfgs` of the `Cmd` instance.
169+
This `OptCfg` vector is set to the public field `cfgs` of the `Cmd` instance.
170170
If you want to access this option configurations, get them from this field.
171171

172172
An option configuration corresponding to each field of an option store is determined by

src/lib.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,42 @@
184184
//! Err(err) => panic!("Invalid option: {}", err.option()),
185185
//! }
186186
//! ```
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="=")]`.
187223
188224
/// Enums for errors that can occur when parsing command line arguments.
189225
pub mod errors;

0 commit comments

Comments
 (0)