This repository was archived by the owner on Sep 14, 2023. It is now read-only.
This repository was archived by the owner on Sep 14, 2023. It is now read-only.
Open
Description
The following example:
use docopt::Docopt;
use serde::Deserialize;
const USAGE: &'static str = "
Test.
Usage:
test [--cache_dir=<cache_dir>]
Options:
--cache_dir=<cache_dir> enables cache
";
#[derive(Debug, Deserialize)]
struct Args {
flag_cache_dir: Option<String>,
}
fn
5D97
main() {
let args: Args = Docopt::new(USAGE)
.and_then(|d| d.deserialize())
.unwrap_or_else(|e| e.exit());
println!("{:?}", args);
}
Gives result:
$ cargo run -- --cache_dir=abc
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
Running `target\debug\docopt-test.exe --cache_dir=abc`
Args { flag_cache_dir: None }
If option name is changed to --cache-dir
, then it parses the optional argument correctly:
Test.
Usage:
test [--cache-dir=<cache_dir>]
Options:
--cache-dir=<cache_dir> enables cache
$ cargo run -- --cache-dir=abc
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target\debug\docopt-test.exe --cache-dir=abc`
Args { flag_cache_dir: Some("abc") }
Metadata
Metadata
Assignees
Labels
No labels