pub struct ArgumentList<'a> {
    pub dangling_values: Vec<String>,
    pub arguments: Vec<Argument>,
    pub parsable_arguments: Vec<&'a mut (dyn HandleableArgument<'a> + 'a)>,
}
Expand description

Acumulates arguments into list which then can be fed to parse.

Examples

use trivial_argument_parser::{ArgumentList, argument::legacy_argument::*};
let mut args_list = ArgumentList::new();
args_list.append_arg(Argument::new(Some('d'), None, ArgType::Flag).unwrap());
args_list.append_arg(Argument::new(Some('p'), None, ArgType::Value).unwrap());
args_list.append_arg(Argument::new(Some('l'), Some("an-list"), ArgType::ValueList).unwrap());

Fields§

§dangling_values: Vec<String>§arguments: Vec<Argument>§parsable_arguments: Vec<&'a mut (dyn HandleableArgument<'a> + 'a)>

Implementations§

source§

impl<'a> ArgumentList<'a>

source

pub fn arguments(&self) -> &Vec<Argument>

source

pub fn new() -> ArgumentList<'a>

Create ArgumentList with empty vector of arguments.

source

pub fn append_arg(&mut self, argument: Argument)

Append argument to the end of the list.

source

pub fn append_dangling_value(&mut self, value: &str)

Append dangling values.

source

pub fn search_by_short_name(&self, name: char) -> Option<&Argument>

Search arguments by short name.

source

pub fn search_by_short_name_mut(&mut self, name: char) -> Option<&mut Argument>

Search arguments by short name.

source

pub fn search_by_long_name(&self, name: &str) -> Option<&Argument>

source

pub fn search_by_long_name_mut(&mut self, name: &str) -> Option<&mut Argument>

Search arguments by long name.

source

pub fn get_dangling_values(&self) -> &Vec<String>

Returns vector of all generated dangling values (values not attached to any argument)

source

pub fn parse_args(&mut self, input: Vec<String>) -> Result<(), String>

Function that does all the parsing. You need to feed user input as an argument. Handles both legacy type arguments and parsable value arguments. When used with mixed type arguments, parsable arguments cannot be accessed before all borrows to ArgumentList are released or it gets dropped.

Examples
use trivial_argument_parser::{
    ArgumentList, args_to_string_vector,
    argument::{
        legacy_argument::*,
        parsable_argument::ParsableValueArgument,
        ArgumentIdentification
    }
};

let mut args_list = ArgumentList::new();
args_list.append_arg(Argument::new(Some('d'), None, ArgType::Flag).unwrap());
let mut argument_str = ParsableValueArgument::new_string(ArgumentIdentification::Long(String::from("hello")));
args_list.register_parsable(&mut argument_str);
args_list.parse_args(args_to_string_vector(std::env::args())).unwrap();
// First read legacy arguments.
args_list.search_by_short_name('n');
// Then access parsable value arguments since last reference was used.
argument_str.first_value();
source

pub fn register_parsable(&mut self, arg: &'a mut impl HandleableArgument<'a>)

Registers argument mutable borrow to be used while parsing.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for ArgumentList<'a>

§

impl<'a> !Send for ArgumentList<'a>

§

impl<'a> !Sync for ArgumentList<'a>

§

impl<'a> Unpin for ArgumentList<'a>

§

impl<'a> !UnwindSafe for ArgumentList<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.