-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Truncated, falsy arguments starting with --no #38
Comments
This is an undocumented feature. A common pattern with command-line options is to have a lone option starting with
If an option is given to Minimist as
|
Let's document it, it's pretty universal (yargs does it too). |
Ah good to know. We ended up going with |
Let's keep this open to track updating the docs. |
For interest, same issue in a Minimist fork: meszaros-lajos-gyorgy/minimist-lite#10 |
Also, remove old security warning. Fixes: minimistjs#38
Very surprising indeed. We added a |
I’m surprised that’s surprising, but either way we should update our docs to make it clear. |
Ok, I can explain why it is surprising: We have several flags, for example:
Leading to a minor bug, because when reading the README on NPM one didn't learn about this behavior. |
I will say that it seems reasonable to me to have |
Just checking I correctly understand what you saw @JonnyBurger . Did you mean // note: declaring `no-open` here is doomed, but trying to reproduce description
var argv = require('minimist')(process.argv.slice(2), {
boolean: ['no-open', 'headless']
});
console.log(argv); % node index.js
{ _: [], 'no-open': false, headless: false }
% node index.js --no-open
{ _: [], 'no-open': false, headless: false, open: false } Basically there is currently only |
I am not a fan of multiple versions of flags being stored, but it is an interesting idea to avoid surprises at runtime in this case. What did you mean by "but be non-enumerable" @ljharb ? (That it doesn't show up when parse result logged?) |
Yep, what i mean is, if you Get the property directly it'll work, otherwise it'll be pretty hard to know it's there. |
@shadowspawn Yes, you got it correctly! I am using the The feature is fine, but not documented and therefore I was surprised. Also, the other reason I got confused is because I used TypeScript users might still get trapped even if the property is non-enumerable. |
Oh, interesting, investigating... I was able to reproduce the autocomplete behaviour, but for me it is coming from GitHub Copilot. With GitHub Copilot active I see I checked So still an interesting detail, but different source of autocomplete. |
An intriguing idea, but too magical for my liking. It would certainly confuse me if I noticed that an option was set in an "invisible" way compared with logging. (See also next comment.) |
In this case, parsing Commander and Yargs both have support for parsing My preferred approach for now is still to add this to the documentation and not change the code. However, this has been a useful discussion and I have moved #48 to draft so I can take another look and extend what I wrote. The extra comments and discussion here make me think it deserves some text and not just buried in the big example. |
Also, remove old security warning. Fixes: minimistjs#38
Also, remove old security warning. Fixes: minimistjs#38
Also, remove old security warning. Fixes: minimistjs#38
Also, remove old security warning. Fixes: minimistjs#38
For interest, I saw that Deno 1.23 switched to |
For interest, the undocumented document "--no-XXX" handling I had to read the source code to diagnose why |
Another related issue on original Minimist repo: Truncate --no-* for args |
Odd behaviour?
The text was updated successfully, but these errors were encountered: