pub struct OptCfg {
pub store_key: String,
pub names: Vec<String>,
pub has_arg: bool,
pub is_array: bool,
pub defaults: Option<Vec<String>>,
pub desc: String,
pub arg_in_help: String,
pub validator: fn(store_key: &str, name: &str, arg: &str) -> Result<(), InvalidOption>,
}
Expand description
Represents an option configuration for how to parse command line arguments.
And this is also used when creating the help text for command line arguments.
Fields§
§store_key: String
Is the key to store option value(s) in the option map in a Cmd
instance.
If this key is not specified or empty, the first element of the names
field is used
instead.
names: Vec<String>
Is the vector for specifying the option name and the aliases.
The order of the names
in this array are used in a help text.
has_arg: bool
Is the flag which allow the option to take option arguments.
is_array: bool
Is the flag which allow the option to take multiple option arguments.
defaults: Option<Vec<String>>
Is the Option
of the vector to specify default value(s) for when the comand option is not
given in command line arguments.
If this value is None
, the default value(s) is not specified.
desc: String
Is the string field to set the description of the option which is used in a help text.
arg_in_help: String
Is the field to set a display string of the option argument(s) in a help text.
An example of the display is like: -o, --option <value>
.
validator: fn(store_key: &str, name: &str, arg: &str) -> Result<(), InvalidOption>
Is the function pointer to validate the option argument(s).
If the option argument is invalid, this funciton returns a
InvalidOption::OptionArgIsInvalid
instance.
Implementations§
Source§impl OptCfg
impl OptCfg
Sourcepub fn with<'a>(params: impl IntoIterator<Item = OptCfgParam<'a>>) -> OptCfg
pub fn with<'a>(params: impl IntoIterator<Item = OptCfgParam<'a>>) -> OptCfg
Creates a OptCfg
instance in a manner similar to named parameters.
use cliargs::OptCfg;
use cliargs::OptCfgParam::{names, has_arg, desc};
let cfg = OptCfg::with([
names(&["foo-bar", "f"]),
has_arg(true),
desc("this is foo-bar option."),
]);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OptCfg
impl RefUnwindSafe for OptCfg
impl Send for OptCfg
impl Sync for OptCfg
impl Unpin for OptCfg
impl UnwindSafe for OptCfg
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more