sindresorhus / meow

🐈 CLI app helper
MIT License
3.53k stars 150 forks source link

Add `allowUnknownFlags` options #169

Closed weareoutman closed 3 years ago

weareoutman commented 3 years ago

fix #126

To simplify figuring out which flags are unknown, I tried:

  1. Pass unknown-options-as-args to yargs-parser first;
  2. Filter unknown options collected in argv._ which starts with -.

And I also make allowUnknownFlags be true by default to keep compatibility.

Let me know if I missed something.

sindresorhus commented 3 years ago

In the future, don't force push. It makes it impossible for me to see what changed, and I'm forced to re-review all the code.

weareoutman commented 3 years ago

In the future, don't force push. It makes it impossible for me to see what changed, and I'm forced to re-review all the code.

👌 Sorry for that, force pushed like my daily work and forgot about the review thing.

kristian commented 3 years ago

Just a suggestion, shouldn't the process rather fail with a exit code of 1 instead of 2? 2 is used when outputting the help and could be considered "not an error". Whereas if allowUnknownFlags is set to false, a unknown flag could be considered an error and thus should fail the process with an 1 insted of a 2?

This assumtion could be backed by the help outputting to stdout, instead of stderr for unknown flags.

sindresorhus commented 3 years ago

Exit code 2 is the convention for invalid flags or other invalid usage: https://stackoverflow.com/questions/1101957/are-there-any-standard-exit-status-codes-in-linux/40484670#40484670

An exit code higher than 1 is AFAIK always an error.

sholladay commented 3 years ago

In the future, don't force push. It makes it impossible for me to see what changed, and I'm forced to re-review all the code.

@sindresorhus if you click on the phrase "force-pushed", it will actually show you the diff. Maybe Refined GitHub could make this more intuitive / discoverable.

sindresorhus commented 3 years ago

Neat. I don't think it always did that though.