docopt.rs
docopt.rs copied to clipboard
Support newtype pattern
Looks like deserializing newtypes is not supported yet.
Code to reproduce:
extern crate docopt;
extern crate rustc_serialize;
use docopt::Docopt;
static USAGE: &'static str = "
Usage: cli_client [-i ID]
Options:
-i ID A client id.
";
#[derive(RustcDecodable, Debug)]
pub struct ClientId(pub u32);
#[derive(RustcDecodable, Debug)]
struct Args {
flag_i: Option<ClientId>,
}
fn main() {
println!("Hello, world!");
let args: Args = Docopt::new(USAGE).and_then(|d| d.decode())
.unwrap_or_else(|e| e.exit());
println!("{:?}", args);
}
Running this without arguments works:
[master]danilo@t410:test$ cargo run
Running `target/debug/test`
Hello, world!
Args { flag_i: None }
But when specifying an argument, parsing fails:
[master]danilo@t410:test$ cargo run -- -i 123
Running `target/debug/test -i 123`
Hello, world!
thread '<main>' panicked at 'Unrecognized struct field: '_field0'', /home/danilo/.multirust/toolchains/stable/cargo/registry/src/github.com-88ac128001ac3a9a/docopt-0.6.80/src/dopt.rs:481
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Process didn't exit successfully: `target/debug/test -i 123` (exit code: 101)