Skip to content
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

Error on unsupported CLI arguments #2623

Closed
wants to merge 7 commits into from
Closed

Conversation

mnsn
Copy link

@mnsn mnsn commented Feb 3, 2017

Summary
I fixed issue #2600 , by listening to the commander event emitter and exit with error when unknown flag is been added

@mnsn mnsn closed this Feb 10, 2017
@chrisbujok
Copy link

@mnsn Can I ask why did you close this PR? I was thinking about solving the issue you mentioned.

@mnsn
Copy link
Author

mnsn commented Feb 15, 2017

The unit tests failed I need to check what I broke

@chrisbujok
Copy link

Sure. Please let me know if I can help - I'd be really happy to fix this issue.

@mnsn mnsn reopened this Feb 18, 2017
@mnsn
Copy link
Author

mnsn commented Feb 18, 2017

I fixed the issues, thank you for the offering Chris.
Maybe Do you understand what is the problem with appveyor ? And how to solve it?

@bestander
Copy link
Member

bestander commented May 12, 2017

Hey, @mnsn.
Thanks for the PR, it can catch a bunch of unexpected errors.

However allowing unsupported flags is a feature, this way Yarn achieves forwards compatibility, e.g. a new flag is used in a build system but not whole organization has updated to using the new version.

How about we just print a warning when flag is unrecognized?

Sorry for a delay in review, the title did was not inviting very much :)
Are you up to rebase and fix?

@bestander bestander changed the title Fix the issue #2600 Error on unsupported CLI arguments May 12, 2017
@bestander
Copy link
Member

Closing for now, looking for people to give it another go

@bestander bestander closed this Jun 23, 2017
@jseminck
Copy link
Contributor

I'd like to take a look at this. I can base myself on the original code from this PR, but change it to warn instead of error?

@bestander
Copy link
Member

@jseminck, yep, give it a try

@jseminck
Copy link
Contributor

jseminck commented Jun 28, 2017

I had a look into this issue, and it seems rather hard.

First of all, I noticed yarn doesn't use the most recent version of commander.js. Are there any plans to upgrade?

The only way I see to get the array of unknown options from commander.js is by listening to the command: event: https://github.com/tj/commander.js/blob/master/index.js#L627

However, yarn has some special logic to deal with an issue in commander.js: and adds + removes some special 'this-arg-will-get-stripped-later' argument:
https://github.com/yarnpkg/yarn/blob/master/src/cli/index.js#L105
https://github.com/yarnpkg/yarn/blob/master/src/cli/index.js#L114

That means that to listen to the correct command event, we'd need to listen to:

commander.on('this-arg-will-get-stripped-later', (args, unknown) => {
  console.log('unknown', unknown);
))

But listening to a specific command in commander.js, will also get it removed from the arguments array (see again: https://github.com/tj/commander.js/blob/master/index.js#L627 - thus making the code in cli/index.js#L114 unnecessary anymore.

This all seems to make things rather more complicated inside yarn.

My suggestion would be to make a PR to commander.js and also pass unknown as an arg to command:* listeners: https://github.com/tj/commander.js/blob/master/index.js#L629 (unless there is a specific reason why they did not do that).

Then in yarn we can listen to that event and get the unknown options from there.

WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants