mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
feat(macros): add convenience macro to get a typed value
This commit is contained in:
parent
b67f2e537e
commit
8752700fbb
1 changed files with 16 additions and 0 deletions
|
@ -27,4 +27,20 @@ macro_rules! for_match {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience macro getting a typed value
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! value_t {
|
||||||
|
($m:ident.value_of($v:expr), $t:ty) => {
|
||||||
|
match $m.value_of($v) {
|
||||||
|
Some(v) => {
|
||||||
|
match v.parse::<$t>() {
|
||||||
|
Ok(val) => Ok(val),
|
||||||
|
Err(_) => Err(format!("{} isn't a valid {}",v,stringify!($t))),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => Err(format!("Argument not found"))
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
Loading…
Reference in a new issue