Options

Struct Options 

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

The Options is a collection of AnpOption and OptionGroup.

§Examples

Basic usage

use anpcli::{AnpOption, Options};

let mut options = Options::new();
options.add_option0("v", false, "print verbosely").unwrap();
options.add_option1("output", "output filename").unwrap();
options.add_option2("i", "input", true, "input filename").unwrap();
options.add_option(AnpOption::builder()
                    .long_option("algorithm")
                    .number_of_args(1)
                    .desc("the algorithm used to process file")
                    .build().unwrap());

Set default values. Note that if the default values have a key not found in the actual options, the parser will result in [ParseErr].

use std::collections::HashMap;
use anpcli::Options;

let mut defaults = HashMap::new();
defaults.insert("target".to_string(), "binary".to_string());

let mut options = Options::new();
options.set_defaults(defaults);
options.add_option0("target", true, "the target output format").unwrap();

Implementations§

Source§

impl Options

Source

pub fn new() -> Options

Create a new Options struct.

Source

pub fn has_defaults(&self) -> bool

Check if the Options has any default value.

Source

pub fn set_defaults(&mut self, defaults: HashMap<String, String>)

Set default values for options.

Source

pub fn get_defaults(&self) -> Option<&HashMap<String, String>>

Get the immutable reference of the default values if exists.

Source

pub fn add_option(&mut self, option: AnpOption)

Source

pub fn add_option0( &mut self, opt: &str, has_arg: bool, description: &str, ) -> Result<(), OptionErr>

A convenient way to add AnpOption to the collection.

Also see Self::add_option, Self::add_option1, Self::add_option2, Self::add_required_option

Source

pub fn add_option1( &mut self, opt: &str, description: &str, ) -> Result<(), OptionErr>

A convenient way to add AnpOption to the collection.

Also see Self::add_option, Self::add_option0, Self::add_option2, Self::add_required_option

Source

pub fn add_option2( &mut self, opt: &str, long_opt: &str, has_arg: bool, description: &str, ) -> Result<(), OptionErr>

A convenient way to add AnpOption to the collection.

Also see Self::add_option, Self::add_option0, Self::add_option1, Self::add_required_option

Source

pub fn add_option_group(&mut self, group: OptionGroup)

Add an option group to the collection.

Source

pub fn add_required_option( &mut self, opt: &str, long_opt: &str, has_arg: bool, description: &str, ) -> Result<(), OptionErr>

A convenient way to add required AnpOption to the collection.

Also see Self::add_option, Self::add_option0, Self::add_option1, Self::add_option2

Source

pub fn get_matching_options(&self, opt: &str) -> Vec<String>

For internal usage.

Source

pub fn get_option(&self, opt: &str) -> Option<Rc<RefCell<AnpOption>>>

Source

pub fn get_option_group( &self, option: &AnpOption, ) -> Option<Rc<HashRefCellGroup>>

Source

pub fn get_option_groups(&self) -> HashSet<Rc<HashRefCellGroup>>

Source

pub fn get_options(&self) -> Vec<Ref<'_, AnpOption>>

Source

pub fn get_required_options(&self) -> Vec<Rc<RefCell<Required>>>

Source

pub fn has_long_option(&self, opt: &str) -> bool

Source

pub fn has_option(&self, opt: &str) -> bool

Source

pub fn has_short_option(&self, opt: &str) -> bool

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Options

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 Display for Options

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Options

§

impl !RefUnwindSafe for Options

§

impl !Send for Options

§

impl !Sync for Options

§

impl Unpin for Options

§

impl !UnwindSafe for Options

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.