pub struct Argument {
    pub arg_result: Option<ArgResult>,
    /* private fields */
}
Expand description

Argument struct allows to specify type of expected argument, its names and after parsing contains results. This is the legacy method of defining arguments. Currently using ParsableValueArgument is preffered.

Examples

use trivial_argument_parser::argument::legacy_argument::*;
let mut example_argument = Argument::new(Some('l'), Some("an-list"), ArgType::ValueList).unwrap();

Fields§

§arg_result: Option<ArgResult>

Implementations§

source§

impl Argument

source

pub fn new( short: Option<char>, long: Option<&str>, arg_type: ArgType ) -> Result<Argument, String>

Create new Argument. You need to specify at least one name (short or long) or you can specify both. Parameter arg_type changes how the parsing will treat the argument.

source

pub fn new_short(name: char, arg_type: ArgType) -> Argument

source

pub fn new_long(name: &str, arg_type: ArgType) -> Argument

source

pub fn get_value(&self) -> Result<&str, &'static str>

Method allowing to simplify reading values of a single value type arguments.

Examples
 use trivial_argument_parser::argument::legacy_argument::*;
 use trivial_argument_parser::ArgumentList;
 let mut args_list = ArgumentList::new();
 args_list.append_arg(Argument::new(Some('v'), None, ArgType::Value).unwrap());
 args_list.parse_args(vec![String::from("-v"), String::from("VALUE")]).unwrap();
 let value = args_list.search_by_short_name('v').unwrap().get_value().unwrap();
 println!("Value: {}", value);
source

pub fn get_values(&self) -> Result<&Vec<String>, &'static str>

Method allowing to simplify reading values of a value list type argument.

Examples
 use trivial_argument_parser::{argument::legacy_argument::*, ArgumentList};
 let mut args_list = ArgumentList::new();
 args_list.append_arg(Argument::new(Some('l'), None, ArgType::ValueList).unwrap());
 args_list.parse_args(vec![String::from("-l"), String::from("cos")]).unwrap();
 let list = args_list.search_by_short_name('l').unwrap().get_values().unwrap();
 for e in list
 {
     println!("Value: {}", e);
 }
source

pub fn get_flag(&self) -> Result<bool, &'static str>

Method allowing to simplify reading values of a flag type argument.

Examples
 use trivial_argument_parser::{ArgumentList, args_to_string_vector, argument::legacy_argument::*};
 let mut args_list = ArgumentList::new();
 args_list.append_arg(Argument::new(Some('d'), None, ArgType::Flag).unwrap());
 args_list.parse_args(args_to_string_vector(std::env::args())).unwrap();
 if(args_list.search_by_short_name('d').unwrap().get_flag().unwrap())
 {
     println!("Flag was set");
 }
source

pub fn add_value( &mut self, input_iter: &mut Peekable<&mut Iter<'_, String>> ) -> Result<(), String>

source

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

source

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

source

pub fn arg_type(&self) -> &ArgType

Trait Implementations§

source§

impl Debug for Argument

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.