Struct argparse::argparser::ArgParseResults
[−]
[src]
pub struct ArgParseResults { // some fields omitted }
This type represents the result ofparsing arguments.
Methods
impl ArgParseResults
fn get<T: FromStr>(&self, name: &str) -> Option<T>
Extracts the argument, as long is the value type implements
FromStr
Example
use argparse::{ArgParser, ArgType}; let mut parser = ArgParser::new("runner".into()); parser.add_opt("verbose", Some("false"), 'v', false, "Whether to produce verbose output", ArgType::Flag); // Normally you'd get this from std::env::args().iter() let test_1 = "./runner -v".split_whitespace() .map(|s| s.into()) .collect::<Vec<String>>(); if let Ok(p_res) = parser.parse(test_1.iter()) { if let Some(true) = p_res.get::<bool>("verbose") { // be verbose } }
fn get_with<T, P>(&self, name: &str, parser: P) -> Option<T> where P: ArgGetter<T>
Extracts the argument, using the ArgGetter<T>
that you provided
Note
See documentation for the trait ArgGetter
for more information
Example
use argparse::{ArgParser, ArgType}; let mut parser = ArgParser::new("runner".into()); parser.add_opt("verbose", Some("false"), 'v', false, "Whether to produce verbose output", ArgType::Flag); // Normally you'd get this from std::env::args().iter() let test_1 = "./runner -v".split_whitespace() .map(|s| s.into()) .collect::<Vec<String>>(); let dumb_closure = |_: &str| { Some(true) }; if let Ok(p_res) = parser.parse(test_1.iter()) { if let Some(true) = p_res.get_with::<bool, _>("verbose", dumb_closure) { // be verbose } }