-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Options parsed before validating argument #1460
Comments
Thanks for clear reproduce steps. I didn't expect the behaviour to change from v4 in these areas, but there have been many parsing improvements. I'll do some digging. |
Short version: reproduced, broken from v5. Drat. Long version The PR that changed the behaviour is #1149 which shipped in v5.0.0. It was BIG. There were no explicit unit tests on Which check gets called where is a bit fragile. To some extent I consider |
Thanks for your investigation into this :). I guess a workaround for me at a library-consumer level could be to simply check whether my first argument (extracted directly from I'm not too familiar with the library source code, but since a misspelt command doesn't need an absent |
That is a potential work-around which is easier at the library-consumer level since you know how you structured your CLI. In the library, there is a long line of if-else cases following the unknownOption call. I think I'll need to work through them to see which ones should be checking the options. The previous code checked in two different places and I wanted to cover a third situation, and thought I had found the place to check just once before working through the cases. Too simple! |
Haha no worries, sounds great. Thanks :). |
Update: We realised that an error with code |
The README does mention |
I was focused on You probably realised this when reporting the issue, but I had not included it in my thinking or comments so far! |
Opened draft PR #1464 |
Here's our consumer-level patch:
|
My PR is aimed at the |
Reworked error handling in Commander v7.1.0 to better support suggestions, and prefer unknown-command to unknown-option |
Hi there,
This is a great project, thank you for maintaining this.
We're in the process of upgrading from v4.0.1 to v7.0.0 with the new features. We have a small problem whereby options are being parsed before the arguments themselves are validated.
We were hoping to be able to continue to listen to
command:*
to detect bad arguments, as we've currently hooked it up to our own suggestion engine to provide "did you mean" suggestions for the bad argument. Upgrading to v7.0.0 has broken this functionality for us.E.g.
Another example:
Minimal reproduction:
I dug into the source code a bit and think I found it. It appears to be parsing the options and throwing the error first, before reaching the "command:*" section.
commander.js/index.js
Line 1472 in 034ad9f
Is there a solution or workaround to this that I haven't found? Thanks :).
The text was updated successfully, but these errors were encountered: