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

add config lookup for .implies() #556

Merged
merged 5 commits into from Jul 16, 2016
Merged

add config lookup for .implies() #556

merged 5 commits into from Jul 16, 2016

Conversation

maxrimue
Copy link
Member

This will eventually fix #547

This PR is still a WIP as the new added test passes regardless of whether boolean-negation is turned on or off, however, I'd love to hear what folks think about the general approach already.

@coveralls
Copy link

coveralls commented Jul 15, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 0426bd4 on boolean-negation-in-implies into 3c2e479 on master.

@@ -57,6 +57,23 @@ describe('validation tests', function () {
})
.argv
})

it('should ignore the --no- part if boolean negation is disabled', function (done) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the test isn't async, you can just not accept done as an argument, and then drop the line:

return done()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than:

it('should ignore the --no- part if boolean negation is disabled')

I might put:

it('does not treat --no- as a special case, if boolean negation is disabled'),

Had to read the current test description a few times, I might just be nit-picking though :)

@bcoe
Copy link
Member

bcoe commented Jul 16, 2016

@maxrimue this is looking quite clean, great work \o/

really curious as to why you're not able to get the test to fail! I'm sure it will be something silly.

@maxrimue
Copy link
Member Author

@bcoe
I discovered some logical mistakes and fixed them now. However, there is one big problem: I discovered that .config() and .pkgConf() actually can't be used to set the parser configuration. Yargs only uses pkgUp to determine the configuration that is then handed over to the parser (as seen here).

So the only problem left now is to change the configuration in the test that I've created to boolean-negation: false... Am I missing something, or should we introduce a coding way to change the parser configuration?

@@ -219,6 +219,12 @@ module.exports = function (yargs, usage, y18n) {
const implyFail = []

Object.keys(implied).forEach(function (key) {
let booleanNegation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work in older versions of Node.js, so you'll want to use var.

@bcoe
Copy link
Member

bcoe commented Jul 16, 2016

@maxrimue turning on and off yargs' parsing options is not handled with pkgConf:

the yargs stanza in your application can be used to turn on and off settings for yargs itself, whereas pkgConf allows you to expose a key for your own libraries to manage configuration:

  • the library nyc uses pkgConf to configure an nyc flag that provides configuration.
  • whereas, a library that uses yargs, and wants to turn off some of its parsing settings would use the yargs stanza in their package.json to specify this.

for your test, rather than using pkgConf, try specifying a cwd for yargs:

yargs(['--foo', '--bar', 'false'], './test/fixtures')

^ by doing this, it should load the yargs stanza from your configuration file.

@coveralls
Copy link

coveralls commented Jul 16, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling fb5c489 on boolean-negation-in-implies into 3c2e479 on master.

@maxrimue
Copy link
Member Author

@bcoe Had to change a line to make the pkgUp() call aware of the customisable cwd variable, but thanks to your suggestion everything works now! Ready for final review.

@maxrimue maxrimue changed the title WIP: add config lookup for .implies() add config lookup for .implies() Jul 16, 2016
@bcoe
Copy link
Member

bcoe commented Jul 16, 2016

@maxrimue this looks great to me, there's another pull of @nexdrew's I'd like to land (on yargs-parser) and a fix that I'd like to land for nyc that I just opened, then I'll publish all three fixes to next and we can try things out on a few projects.

@bcoe bcoe merged commit 8d7585c into master Jul 16, 2016
@bcoe bcoe deleted the boolean-negation-in-implies branch July 16, 2016 23:00
@bcoe
Copy link
Member

bcoe commented Jul 16, 2016

@maxrimue give this a spin:

npm cache clear; npm i yargs@next

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.

.implies() ignores parser preferences
3 participants