OptionBuilder

Struct OptionBuilder 

Source
pub struct OptionBuilder { /* private fields */ }
Expand description

An builder struct for AnpOption.

Implementations§

Source§

impl OptionBuilder

Source

pub fn build(self) -> Result<AnpOption, OptionErr>

Build an AnpOption with configured values.

§Error

Returns an error if:

  • option and long_option are not specified.
  • option or long_option is blank or not valid option name.

The valid option name:

  • for a single char - alphabetic only
  • for multiple chars - alphabetic, "@", "?"
Source

pub fn arg_name(self, arg_name: &str) -> Self

Set the argument name of the option.

Source

pub fn option(self, opt: &str) -> Self

Set the short option name.

The short option name is not necessary to have a single char. A short option with multiple chars is also valid, like -required.

Source

pub fn long_option(self, long_opt: &str) -> Self

Set the long option name.

Source

pub fn desc(self, description: &str) -> Self

Set the description of the option.

Source

pub fn has_arg(self, has_arg: bool) -> Self

Set whether the option has exactly one argument or no argument.

Also see Self::has_args and Self::number_of_args.

Source

pub fn has_args(self) -> Self

Set the option to having unlimited number of arguments.

Also see Self::has_arg and Self::number_of_args.

Source

pub fn number_of_args(self, number_of_args: usize) -> Self

Set the option to having exactly number_of_args number of arguments.

Also see Self::has_arg and Self::has_args

Source

pub fn optional_arg(self, is_optional: bool) -> Self

Whether argument(s) is optional.

Source

pub fn required(self, required: bool) -> Self

Whether the option is required to passed to command line.

Source

pub fn value_separator(self, value_sep: char) -> Self

Set the value separator for the option.

For example, when the value separator set to ,, the option value -v=1,2,3 is parsed into three values.

Auto Trait Implementations§

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, 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.