AnpOption

Struct AnpOption 

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

The AnpOption represents a single option.

§Examples

Create an option without argument: -v,--verbose

use anpcli::AnpOption;
let opt = AnpOption::builder().option("v").long_option("verbose").build();

Create an option with single argument: -f <arg>.

use anpcli::AnpOption;
let opt = AnpOption::builder().option("f").has_arg(true).build();

Create an option with multiple arguments: --file [<arg> ...]

use anpcli::AnpOption;
let opt = AnpOption::builder().long_option("file").has_args().optional_arg(true);
let another_opt = AnpOption::builder().long_option("file").number_of_args(3);

Implementations§

Source§

impl AnpOption

Source

pub fn builder() -> OptionBuilder

Create a OptionBuilder to config the option.

Source

pub fn has_arg_name(&self) -> bool

Check if the option has an argument name.

Source

pub fn has_arg(&self) -> bool

Check if the option accepts argument.

Also see Self::has_args

Source

pub fn has_args(&self) -> bool

Check if the option accepts more than one arguments.

Also see Self::has_arg

Source

pub fn has_long_opt(&self) -> bool

Check if the option has a long option name.

Source

pub fn has_no_value(&self) -> bool

Check if the option has a short option name.

Source

pub fn has_optional_arg(&self) -> bool

Check whether the argument if optional

Source

pub fn has_value_separator(&self) -> bool

Check whether the option has value separator.

See OptionBuilder::value_separator

Source

pub fn is_required(&self) -> bool

Check whether the option is required.

Source

pub fn accepts_arg(&self) -> bool

Source

pub fn requires_arg(&self) -> bool

Source

pub fn add_value_for_processing(&mut self, value: &str) -> Result<(), OptionErr>

Source

pub fn clear_values(&mut self)

Source

pub fn get_arg_name(&self) -> Option<&String>

Source

pub fn get_args(&self) -> &ArgCount

Source

pub fn get_description(&self) -> Option<&String>

Source

pub fn get_key(&self) -> &str

Source

pub fn get_id(&self) -> char

Source

pub fn get_long_opt(&self) -> Option<&String>

Source

pub fn get_opt(&self) -> Option<&String>

Source

pub fn get_value<T: FromStr>(&self) -> Option<Result<T, T::Err>>

Source

pub fn get_value_at<T: FromStr>( &self, index: usize, ) -> Option<Result<T, T::Err>>

Source

pub fn get_values<T: FromStr>(&self) -> Vec<Result<T, T::Err>>

Source

pub fn get_value_separator(&self) -> Option<char>

Source

pub fn set_arg_name(&mut self, arg_name: &str)

Source

pub fn set_args(&mut self, num: usize)

Source

pub fn set_description(&mut self, description: &str)

Source

pub fn set_long_option(&mut self, long_option: &str)

Source

pub fn set_optional_arg(&mut self, optional_arg: bool)

Source

pub fn set_required(&mut self, required: bool)

Source

pub fn set_value_separator(&mut self, value_sep: char)

Trait Implementations§

Source§

impl Clone for AnpOption

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AnpOption

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for AnpOption

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Hash for AnpOption

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for AnpOption

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.