Skip to content

Commit

Permalink
feat(macros): add ability to get mutliple typed values or exit
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed Apr 14, 2015
1 parent e243fe3 commit 0b87251
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,25 @@ macro_rules! value_t_or_exit {
}
}
};
($m:ident.values_of($v:expr), $t:ty) => {
match $m.values_of($v) {
Some(ref v) => {
let mut tmp = Vec::with_capacity(v.len());
for pv in v {
match pv.parse::<$t>() {
Ok(rv) => tmp.push(rv),
Err(_) => {
println!("{} isn't a valid {}\n{}\nPlease re-run with --help for more information",pv,stringify!($t), $m.usage());
::std::process::exit(1);
}
}
}
tmp
},
None => {
println!("Argument \"{}\" not found or is not valid\n{}\nPlease re-run with --help for more information",$v, $m.usage());
::std::process::exit(1);
}
}
};
}

0 comments on commit 0b87251

Please sign in to comment.