diff --git a/src/errors/opt_err.rs b/src/errors/opt_err.rs index 40d7821..8172678 100644 --- a/src/errors/opt_err.rs +++ b/src/errors/opt_err.rs @@ -90,7 +90,7 @@ pub enum InvalidOption { /// The store key of the option configuration that caused this error. store_key: String, - /// The option name that caused this error. + /// The duplicated name of the option configuration. name: String, }, diff --git a/src/lib.rs b/src/lib.rs index 1c0240c..484c485 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -545,8 +545,8 @@ impl<'b, 'a> Cmd<'a> { /// Returns the option argument with the specified name. /// /// If the option has multiple arguments, this method returns the first argument. - /// If the option a boolean flag, this method returns [None]. - /// If the option is not specified in the command line argument, the return value + /// If the option is a boolean flag, this method returns [None]. + /// If the option is not specified in the command line arguments, the return value /// of this method is [None]. pub fn opt_arg(&'a self, name: &str) -> Option<&'a str> { if let Some(opt_vec) = self.opts.get(name) { @@ -560,8 +560,8 @@ impl<'b, 'a> Cmd<'a> { /// Returns the option arguments with the specified name. /// /// If the option has one or multiple arguments, this method returns an array of the arguments. - /// If the option a boolean flag, this method returns an empty vector. - /// If the option is not specified in the command line argument, the return value + /// If the option is a boolean flag, this method returns an empty vector. + /// If the option is not specified in the command line arguments, the return value /// of this method is [None]. pub fn opt_args(&'a self, name: &str) -> Option<&'a [&'a str]> { match self.opts.get(name) { diff --git a/src/parse/parse_with.rs b/src/parse/parse_with.rs index 51799a1..ba9a34e 100644 --- a/src/parse/parse_with.rs +++ b/src/parse/parse_with.rs @@ -21,9 +21,21 @@ impl<'b, 'a> Cmd<'a> { /// An option configuration has fields: `store_key`, `names`, `has_arg`, `is_array`, /// `defaults`, `desc`, `arg_in_help`, and `validator`. /// + /// When an option matches one of the `names` in the option configurations, the option is + /// registered into [Cmd] with `store_key`. + /// If both `has_arg` and `is_array` is false, the optioin can have only one option argument, + /// otherwise the option cannot have option arguments. + /// If `defaults` field is specified and no option value is given in command line arguments, + /// the value of `defaults` is set as the option arguments. + /// + /// If options not declared in option configurations are given in command line arguments, this + /// method basicaly returns [UnconfiguredOption] error. + /// However, if you want to allow other ooptions, add an option configuration of which + /// `store_key` or the first element of `names` is "*". + /// /// The ownership of the vector of option configurations which is passed as an argument of - /// this method is moved to this method and set to the public field `cfgs` of [Cmd] instance. - /// If you want to access the option configurations after parsing, get them from this field. + /// this method is moved to this method and set into this [Cmd] instance. + /// It can be retrieved with its method: [Cmd::opt_cfgs]. /// /// ``` /// use cliargs::{Cmd, OptCfg}; @@ -74,6 +86,10 @@ impl<'b, 'a> Cmd<'a> { /// This method parses command line arguments in the same way as the [Cmd::parse_with] method, /// except that it only parses the command line arguments before the first command argument. /// + /// The ownership of the vector of option configurations which is passed as an argument of + /// this method is moved to this method and set into this [Cmd] instance. + /// It can be retrieved with its method: [Cmd::opt_cfgs]. + /// /// ``` /// use cliargs::{Cmd, OptCfg}; /// use cliargs::OptCfgParam::{names, has_arg, defaults, validator, desc, arg_in_help};