swift-argument-parser icon indicating copy to clipboard operation
swift-argument-parser copied to clipboard

Incorrect flag in error message

Open erica opened this issue 5 years ago • 4 comments

In the following example, the caller has substituted a single dash for a double in the sound key/value pair:

% remind -d 20 my reminder -sound tink
Error: The value 'tink' is invalid for '-d <days>'

The error should read:

Error: The value 'tink' is invalid for '-s <seconds>'

erica avatar May 07 '20 15:05 erica

Thanks for the bug report, @erica! Could you show the command declaration for this? I can’t quite get this error to reproduce.

natecook1000 avatar May 08 '20 16:05 natecook1000

Turns out that I've removed -s for seconds, so -s does not match a valid command. But -sound matches the long option --sound. I think the error message should be easy to construct as "used the wrong hyphenation" here

erica avatar May 08 '20 20:05 erica

Ah, that makes more sense! What’s happening is that the parser is first looking to see if something matches -sound, not finding it, and then checking to see if sound is a pack of short options. It finds -d at the end, but tink is an invalid value.

To fix this, we’ll need to decide whether we should do near-miss matching when we partially match (or error while partially matching) on a single-dashed argument.

natecook1000 avatar May 14 '20 17:05 natecook1000

In the following example, the caller has substituted a single dash for a double in the sound key/value pair:

% remind -d 20 my reminder -sound tink
Error: The value 'tink' is invalid for '-d <days>'

The error should read:

Error: The value 'tink' is invalid for '-s <seconds>'

Sorry to bother but is it possible for you to point to the code you're talking about (ie: the part of the code printing the error, and the part where the flag is defined), please?

I'm going through the issues to try and help but I don't know what to do about this one. I'll just move on.

Cheers, — AJ

ViralTaco avatar Jul 12 '20 01:07 ViralTaco