Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Positional arguments are misparsed as --required arguments #258

Open
jyn514 opened this issue Nov 24, 2020 · 4 comments
Open

Positional arguments are misparsed as --required arguments #258

jyn514 opened this issue Nov 24, 2020 · 4 comments

Comments

@jyn514
Copy link

jyn514 commented Nov 24, 2020

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).

@jyn514
Copy link
Author

jyn514 commented Nov 24, 2020

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?

@jyn514
Copy link
Author

jyn514 commented Nov 24, 2020

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.

@BurntSushi
Copy link
Member

BurntSushi commented Nov 24, 2020

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

@jyn514
Copy link
Author

jyn514 commented Nov 24, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants