-
Notifications
You must be signed in to change notification settings - Fork 120
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
feat: allow disabling duplicate-arguments-array #67
Conversation
@@ -544,8 +545,10 @@ function parse (args, opts) { | |||
o[key] = value | |||
} else if (Array.isArray(o[key])) { | |||
o[key].push(value) | |||
} else { | |||
} else if (configuration['duplicate-arguments-array']) { |
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.
Great, that's about as simple as I was hoping it would be 👍
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.
@laggingreflex awesome! thanks for the contribution.
If you wouldn't mind adding a test, so that we stay at 100% coverage, and adding a note about this configuration option in the docs, we'll get this landed ASAP.
This has a slight problem though... it requires you to put |
@laggingreflex you can also manually pass configuration to yargs-parser, which is how yargs actually does it 😄 https://github.com/yargs/yargs-parser/blob/master/test/yargs-parser.js#L1777 ☝️ you should be able to crib that test. |
Can the consumers of yargs be able to pass that configuration to yargs-parser though? Because I originally intended to fix yargs#530 with this. import yargs from 'yargs'
const config = yargs(???).parse('-x 1 -x 2'); It seemed to me the only way for a yargs user to pass this configuration would be by using package.json way - due to how yargs passes "configuration" to yargs-parser ... unless I'm missing something? |
@laggingreflex yargs' is smart enough to read configuration from your projects own package.json; so once you add this setting, a user who wants this behavior, simply needs to add:
To their project's own package.json. |
Lets you disable "duplicates" behaviour ``` yargsParser('-x 1 -x 2') // => {x: [1, 2]} ``` ``` yargsParser('-x 1 -x 2', {configuration:{'duplicate-arguments-array': false}}) // => {x: 2} ```
70b2636
to
d23b473
Compare
@laggingreflex I'm really happy with this, will work on getting this landed ASAP. |
@laggingreflex mind rebasing, I think I landed your other pull request in the wrong order. |
@laggingreflex if you checkout |
This already has been landed. #71 included commits for both this (#67) and itself so as far as the matter is of landing this PR, it has already been done; it was included in #71 and the changes have landed successfully. The only (minor?) problem is that the two commits have been squashed into one 0f0fb2d which makes no mention of this PR (#67), but only that of #71 (in the commit message). If it's not a big problem then you may close this PR. If however you do want separate commits then I think you probably will need to re-write history a bit. I did try to rebase but it gives me "nothing to commit", because like I said, the changes have already landed in latest master. |
For yargs#530
Lets you disable "duplicates" behaviour