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
Make strict() work with options containing hyphens #1414
Conversation
test/usage.js
Outdated
@@ -810,6 +810,15 @@ describe('usage tests', () => { | |||
r.should.have.property('exit').and.equal(true) | |||
}) | |||
|
|||
it('fails when an invalid argument is provided with automatic camel case', (done) => { | |||
return yargs('--foo-bar') |
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.
prior to your fix would the following also fail?
yargs('--foo-bar')
.option('foo-bar', {describe: 'foo bar option'})
.strict()
.fail((msg) => {
return done()
})
.argv
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.
I’m not sure why you’re asking about that, but both before and after my fix, with that code, argv
returns {'foo-bar': true, 'fooBar': true}
instead of failing.
thanks for the contribution @andrewdotn, I think we should add a couple more test cases for the happy paths, but this looks like it's on the right track. |
lib/validation.js
Outdated
@@ -96,7 +96,7 @@ module.exports = function validation (yargs, usage, y18n) { | |||
if (specialKeys.indexOf(key) === -1 && | |||
!positionalMap.hasOwnProperty(key) && | |||
!yargs._getParseContext().hasOwnProperty(key) && | |||
!aliases.hasOwnProperty(key) | |||
!self.isValidAndNotMadeUpAlias(key, aliases) |
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.
let's call this, isValidAndNotNewAlias
, just to match naming.
Hello @bcoe, I’ve renamed that method and added some more tests. Anything more to get this merged? |
@andrewdotn could you please give the following a try:
And let me know if everything is working as expected? |
@bcoe Yup, confirmed working, thanks! Test file:
Before:
|
@andrewdotn sorry that it took a while to get a release out the door; this work should now be available in Let me know if you bump into any issues, and thank you for your contribution! |
Fixes #1039 #1171 #1236 #1325