Struct OptCfg

Source
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

Source

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§

Source§

impl Debug for OptCfg

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T