Do you want to request a feature or report a bug?
bug
What is the current behavior?
When you provide yarn an invalid command-line option, it just ignores it. This behavior hides typos and errors. For example, if you provide the command-line option --pore-lockfile rather than seeing an error about the incorrect command-line option, your yarn.lock may get overwritten.
If the current behavior is a bug, please provide the steps to reproduce.
$ yarn --sadfasdfas
yarn install v0.23.4
[1/4] 🔍 Resolving packages...
success Already up-to-date.
✨ Done in 0.29s.
What is the expected behavior?
yarn should print an error that the command-line option is not recognized and exit with a non-zero status.
Please mention your node.js, yarn and operating system version.
$ node --version
v7.9.0
$ yarn --version
0.23.4
$ uname -a
Darwin mbp.local 15.6.0 Darwin Kernel Version 15.6.0: Fri Feb 17 10:21:18 PST 2017; root:xnu-3248.60.11.4.1~1/RELEASE_X86_64 x86_64
It should send a warning, PR is welcome.
Commander.js emits an event when argument is unknown, just print reproter.warn with error message.
@bestander I'd like to take this up as my first contribution to yarn.
I think I have isolated the issue to L83-87 of src/cli/index.js.
I've only just begun digging into the code base, but it looks like this problem also extends to every command. If you provide an invalid flag to a command, it seems to just ignore it and complete its task as intended. Is that an intended feature?
@yeskunall, welcome!
Give it a try, also I think commander.js throws and exception when there is an unknown CLI param.
Maybe you could add a warning in the exception handler
Awesome! Thanks for the quick response!
commander, from what I understand _does_ throw an exception in the form of a console.error(); with the error message. What's weird is when you first instantiate a commander object, it sets a flag called _allowUnknownOption to false, which should technically throw an error and then, according to the docs, simple die.
Are we overriding this default setting somewhere?
Also, when you say exception handler, are you referring to the warn methods in each of the reporters (for example, the JSONReporter)? Sorry if I'm asking completely bizarre questions. 😟
That is ok.
I think commander should have something like
commander.onUnkonwnCommandException((error) => {reporter.warn(error)}).
On 23 June 2017 at 11:13, Kunall Banerjee ✌️ notifications@github.com
wrote:
Awesome! Thanks for the quick response!
commander, from what I understand does throw an exception, but in the
form of a console.error(); with the error message. What's weird is when
you first instantiate a commander object, it sets a flag
https://github.com/tj/commander.js/blob/master/index.js#L86 called
_allowUnknownOption to false, which should technically throw an error and
then, according to the docs, simple die.
Are we overriding this default setting somewhere?Also, when you say exception handler, are you referring to the warn
methods in each of the reporters (for example, the JSONReporter)? Sorry
if I'm asking completely bizarre questions. 😟—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/yarnpkg/yarn/issues/3317#issuecomment-310736167, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACBdWKD6ZXpT6O_9n9ZIHlyef5BAt1ckks5sHAAxgaJpZM4NQoGH
.
@yeskunall have a look at this https://github.com/yarnpkg/yarn/pull/2623.
Would be great if you take over
Yes, I will look into it!
--
Kunall Banerjee
So @bestander, after spending some time on this, I have not been able to fix this.
As I mentioned before, we can enable or disable unknown options using commander#allowUknownOption, but that's not what we're looking for here. I also tried attaching an event listener to the commander object like so:
commander.on(commandName, (args, unknown) => {
commander.args.unshift(commandName);
if (unknown && unknown.length > 0) {
reporter.warnreporter.lang('unknownFlag', unknown[0]));
}
});
but that doesn't seem to work either. Any pro tips?
sorry, not a pro here, hoping someone could help us here :)
Duplicate of #2600.