docopt/docopt.rs

Positional arguments are misparsed as --required arguments

Opened this issue · 4 comments

const MAIN_USAGE: &str = "
Usage:
    cargo deadlinks [--dir <directory>]
";

fn main() {
    let args: MainArgs = Docopt::new(MAIN_USAGE)
        .and_then(|d| {
            d.version(Some(env!("CARGO_PKG_VERSION").to_owned()))
                .deserialize()
        })
        .unwrap_or_else(|e| e.exit());
    dbg!(&args);
$ /home/joshua/.local/lib/cargo/target/debug/cargo-deadlinks deadlinks -- --document-private
[src/bin/cargo-deadlinks.rs:46] &args = MainArgs {
    arg_directory: Some(
        "--document-private",
    ),
}

This is wrong - docopt should either exit with an error or ignore the flag altogether (my preference is to exit with an error).

Hmm, looking at http://docopt.org/ it looks like this is intended behavior, since [--dir <directory>] is the same as [--dir] [<directory>]? Why is the -- being ignored, though?

For context, this is what I originally wanted to do:

Usage:
    cargo deadlinks [--dir <directory>] [options] [-- <cargo_arguments>...]

but cargo deadlinks -- --document-private-items was treating document-private as the <directory>, not part of cargo_arguments.

I don't know, sorry. I haven't used docopt in years. In your last issue, I pointed you to the project status.

I guess that wasn't enough to scare you off. I've emboldened the message: https://github.com/docopt/docopt.rs#this-crate-is-unmaintained

Ok, no problem. I hadn't switched because I hadn't had the time. Last night I ended up rewriting this with pico args and it turned out pretty well I think: deadlinks/cargo-deadlinks#116

Feel free to close this if you don't plan to fix it.