pirate/tests/main.rs

34 lines
821 B
Rust
Raw Normal View History

2015-04-28 01:10:37 -04:00
extern crate pirate;
use std::env;
use pirate::{Matches, MatchesTrait, matches, usage, vars};
2015-04-28 01:10:37 -04:00
fn main() {
let env_args: Vec<String> = env::args().collect();
let opts = vec!["o/opt(An option)", "a(An Argument):"];
let mut vars = vars("test", &opts).unwrap();
let matches: Matches = match matches(&mut vars, &env_args) {
2015-06-10 18:14:11 +00:00
Ok(m) => m,
Err(why) => panic!("An error occurred: {}", why)
2015-04-28 01:10:37 -04:00
};
if matches.has_match("help") {
usage(&vars);
return;
}
let arg = match matches.get("a") {
Some(a) => a.clone(),
None => String::from("Pickle")
};
match matches.get("opt") {
Some(_) => println!("Opt was passed to the program"),
None => println!("Opt was not passed to the program")
2015-04-28 01:10:37 -04:00
}
println!("{}", arg);
2015-04-28 01:10:37 -04:00
}