8000 Optional argument parsed as None instead of Some(_) if using '_' in option name · Issue #254 · docopt/docopt.rs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content 8000
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.
Optional argument parsed as None instead of Some(_) if using '_' in option name #254
Open
@mrowqa

Description

@mrowqa

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0