mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
feat(macros): add ability to get a typed multiple values
This commit is contained in:
parent
4b7cd3ea49
commit
e243fe38dd
1 changed files with 24 additions and 2 deletions
|
@ -40,7 +40,29 @@ macro_rules! value_t {
|
||||||
Err(_) => Err(format!("{} isn't a valid {}",v,stringify!($t))),
|
Err(_) => Err(format!("{} isn't a valid {}",v,stringify!($t))),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => Err(format!("Argument not found"))
|
None => Err(format!("Argument \"{}\" not found", $v))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
($m:ident.values_of($v:expr), $t:ty) => {
|
||||||
|
match $m.values_of($v) {
|
||||||
|
Some(ref v) => {
|
||||||
|
let mut tmp = Vec::with_capacity(v.len());
|
||||||
|
let mut err = None;
|
||||||
|
for pv in v {
|
||||||
|
match pv.parse::<$t>() {
|
||||||
|
Ok(rv) => tmp.push(rv),
|
||||||
|
Err(_) => {
|
||||||
|
err = Some(format!("{} isn't a valid {}",pv,stringify!($t)));
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match err {
|
||||||
|
Some(e) => Err(e),
|
||||||
|
None => Ok(tmp)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => Err(format!("Argument \"{}\" not found", $v))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -60,7 +82,7 @@ macro_rules! value_t_or_exit {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
println!("Argument not found\n{}\nPlease re-run with --help for more information", $m.usage());
|
println!("Argument \"{}\" not found or is not valid\n{}\nPlease re-run with --help for more information",$v, $m.usage());
|
||||||
::std::process::exit(1);
|
::std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue