2018-03-09 15:52:50 +00:00
|
|
|
#[macro_use]
|
2018-07-02 18:45:17 +00:00
|
|
|
extern crate clap;
|
2018-03-09 15:52:50 +00:00
|
|
|
|
2018-07-02 18:45:17 +00:00
|
|
|
use clap::Clap;
|
2018-03-29 22:15:22 +00:00
|
|
|
use std::error::Error;
|
2018-03-09 15:52:50 +00:00
|
|
|
|
2018-03-29 22:15:22 +00:00
|
|
|
fn parse_key_val<T, U>(s: &str) -> Result<(T, U), Box<Error>>
|
|
|
|
where
|
|
|
|
T: std::str::FromStr,
|
|
|
|
T::Err: Error + 'static,
|
|
|
|
U: std::str::FromStr,
|
|
|
|
U::Err: Error + 'static,
|
|
|
|
{
|
2018-07-02 18:45:17 +00:00
|
|
|
let pos = s
|
|
|
|
.find('=')
|
2018-05-21 14:54:22 +00:00
|
|
|
.ok_or_else(|| format!("invalid KEY=value: no `=` found in `{}`", s))?;
|
2018-03-29 22:15:22 +00:00
|
|
|
Ok((s[..pos].parse()?, s[pos + 1..].parse()?))
|
2018-03-09 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 18:45:17 +00:00
|
|
|
#[derive(Clap, Debug)]
|
2018-03-09 15:52:50 +00:00
|
|
|
struct Opt {
|
2018-07-02 18:45:17 +00:00
|
|
|
#[clap(short = "D", parse(try_from_str = "parse_key_val"))]
|
2018-03-29 22:15:22 +00:00
|
|
|
defines: Vec<(String, i32)>,
|
2018-03-09 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2018-07-02 18:45:17 +00:00
|
|
|
let opt = Opt::parse();
|
2018-03-09 15:52:50 +00:00
|
|
|
println!("{:?}", opt);
|
|
|
|
}
|