pacak / bpaf

Command line parser with applicative interface
337 stars 17 forks source link

Incorrect error message "no such flag" with valid option #350

Closed wg closed 5 months ago

wg commented 5 months ago

Hi @pacak, thanks again for bpaf! I'm migrating some projects at work to it and ran into an incorrect error message which I've reduced to this case:

struct Args {
    a: u64,
    b: u64,
}

fn parser() -> OptionParser<Args> {
    let a = long("a").argument("a");
    let b = long("b").argument("b");
    construct!(Args { a, b }).to_options()
}

When run with arguments --b 1 bpaf outputs no such flag: `--b`, did you mean `--a`?

pacak commented 5 months ago

Ouch. It tries to parse items sequentially, first a, then b, a is missing so it gives up right away with both --b and - marked as "unparsed". Then it tries to come up with a good error message and gets it all wrong. I'm surprised it never came up before.

I see two possible fixes - one is to be a bit more lazy at failing and try to parse b, the other one is to try to be a bit more careful when wording errors. --b is a valid flag and it knows it.

Thank you for a good test case, I'll see what I can do about it tomorrow.

pacak commented 5 months ago

Okay, I have a fix and fixing that improved some other error messages. I'll try to make a new release this weekend.

wg commented 5 months ago

Looks good here, bpaf is a real joy to use, thank you for it and for the quick release!