From 0b87251fc088234bee51c323c2b652d7254f7a59 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Tue, 14 Apr 2015 14:11:29 -0400 Subject: [PATCH] feat(macros): add ability to get mutliple typed values or exit --- src/macros.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/macros.rs b/src/macros.rs index 520dc9fc28b..a1c59da93c3 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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); + } + } + }; } \ No newline at end of file