-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add allowUnknownFlags
options
#169
Add allowUnknownFlags
options
#169
Conversation
1333c1d
to
fc33c0f
Compare
fc33c0f
to
30c2e44
Compare
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. |
test('spawn CLI and test specifying unknown flags', async t => { | ||
const error = await t.throwsAsync( | ||
execa(fixtureAllowUnknownFlags, ['--foo', 'bar', '--unspecified-a', '--unspecified-b', 'input-is-allowed']) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message
can be tested in t.throwsAsync
directly.
index.js
Outdated
@@ -54,6 +54,11 @@ const reportMissingRequiredFlags = missingRequiredFlags => { | |||
} | |||
}; | |||
|
|||
const reportUnknownFlags = unknownFlags => { | |||
console.error(`Unknown flag${unknownFlags.length > 1 ? 's' : ''}`); | |||
console.error(unknownFlags.join('\n')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. One console
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed both.
👌 Sorry for that, force pushed like my daily work and forgot about the review thing. |
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 This assumtion could be backed by the help outputting to stdout, instead of stderr for unknown flags. |
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. |
@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. |
Neat. I don't think it always did that though. |
fix #126
To simplify figuring out which flags are unknown, I tried:
argv._
which starts with-
.And I also make
allowUnknownFlags
betrue
by default to keep compatibility.Let me know if I missed something.