Skip to content
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.

argument name with _ underscore is misaligned to - hyphen #229

@rbuckland

Description

@rbuckland

When an argument has an _ in the docopt, deserialising it to the Args struct fails as it is looking for an argument with an _

Example error

18:10 $ cargo run -- /
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/bar /`
Could not find argument '<foo-path>' (from struct field 'arg_foo_path').
Note that each struct field must have the right key prefix, which must
be one of `cmd_`, `flag_` or `arg_`.

Code sample causing error

#[macro_use]
extern crate serde_derive;
extern crate docopt;

use docopt::Docopt;

const USAGE: &'static str = "
JSON XPather

Usage:
  bar <foo_path>

";

#[derive(Debug, Deserialize)]
struct Args {
    arg_foo_path: String,
}


fn main() {
    let args: Args = Docopt::new(USAGE)
                            .and_then(|d| d.deserialize())
                            .unwrap_or_else(|e| e.exit());
    println!("{:?}", args);
}

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