Struct trivial_argument_parser::argument::legacy_argument::Argument
source · 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
impl Argument
sourcepub fn new(
short: Option<char>,
long: Option<&str>,
arg_type: ArgType
) -> Result<Argument, String>
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.
pub fn new_short(name: char, arg_type: ArgType) -> Argument
pub fn new_long(name: &str, arg_type: ArgType) -> Argument
sourcepub fn get_value(&self) -> Result<&str, &'static str>
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);
sourcepub fn get_values(&self) -> Result<&Vec<String>, &'static str>
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);
}
sourcepub fn get_flag(&self) -> Result<bool, &'static str>
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");
}
pub fn add_value( &mut self, input_iter: &mut Peekable<&mut Iter<'_, String>> ) -> Result<(), String>
pub fn short(&self) -> &Option<char>
pub fn long(&self) -> &Option<String>
pub fn arg_type(&self) -> &ArgType
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Argument
impl Send for Argument
impl Sync for Argument
impl Unpin for Argument
impl UnwindSafe for Argument
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more