docopt.rs
docopt.rs copied to clipboard
Can't decode paths
Surely someone has written a program that uses files, so I'm wondering if I'm the one doing something wrong?
It looks like, when encountering a PathBuf field, docopt parses the argument as a number, and fills the PathBuf with a single byte with that value.
extern crate docopt;
extern crate rustc_serialize;
use docopt::Docopt;
use std::path::PathBuf;
static USAGE: &'static str = "
foo generator.
Usage:
foo <path>
Options:
-h --help Show this screen.
";
#[derive(Debug, RustcDecodable)]
struct Args {
arg_path: PathBuf,
}
fn main() {
{
let argv = ["foo", "97"];
let args: Args = Docopt::new(USAGE)
.unwrap()
.argv(argv.iter())
.decode()
.unwrap();
println!("{:?}", args); // Args { arg_path: "a" }
}
{
let argv = ["foo", "some/path"];
let args: Args = Docopt::new(USAGE)
.unwrap()
.argv(argv.iter())
.decode()
.unwrap(); // panics
}
}
Because decoding PathBuf is decoding Vec<u8>, I'm assuming that docopt mistakes a PathBuf option for a u8 option that can be passed multiple times (note that Vec<PathBuf> still doesn't work).