mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
feat(macros): add ability to get mutliple typed values or exit
This commit is contained in:
parent
e243fe38dd
commit
0b87251fc0
1 changed files with 21 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue