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

Disable "duplicates" behaviour #530

Closed
stevage opened this issue Jun 21, 2016 · 8 comments
Closed

Disable "duplicates" behaviour #530

stevage opened this issue Jun 21, 2016 · 8 comments

Comments

@stevage
Copy link

stevage commented Jun 21, 2016

If you specify a flag multiple times it will get turned into an array containing all the values in order.

$ node examples/reflect.js -x 5 -x 8 -x 0
{ _: [], x: [ 5, 8, 0 ], '$0': 'examples/reflect.js' }

This is surprising, and undesirable behaviour to me. I'd expect the last argument to override the previous ones. Is there a way to achieve this?

@bcoe
Copy link
Member

bcoe commented Jun 21, 2016

what if we added array parsing as one the optional configuration settings in yargs-parser?

https://github.com/yargs/yargs-parser#configuration

@stevage
Copy link
Author

stevage commented Jun 21, 2016

Yep, something like:

  • "duplicate-arguments": "array" (current behaviour)
  • "duplicate-arguments": "last" (keep the rightmost)
  • "duplicate-arguments": "first" (keep the first)

Possibly an option where subsequent arguments are not interpreted as that argument. So app --foo --foo is interpreted as having a foo boolean argument, and a freetext positional argument whose value is --foo.

@bcoe
Copy link
Member

bcoe commented Jun 21, 2016

@stevage my temptation is to start simple, with:

array: true <-- current behavior.
array: false <-- take the last argument provided.

I think this would address 99% of use-cases, without making the configuration too complicated.

@stevage
Copy link
Author

stevage commented Jun 21, 2016

Agree with the 99% of the use cases bit, but with boolean values you're closing the door to supporting the others later.

@bcoe
Copy link
Member

bcoe commented Jun 21, 2016

@stevage my temptation would be to support the 99% case, and we can revisit this decision in the future.

I'll make an effort to get this additional configuration option implemented at some point this weekend (I'm hoping to have some cycles to hack on OSS).

@pluma
Copy link

pluma commented Nov 8, 2016

@bcoe I gather you didn't get as many cycles to hack on OSS as you were anticipating. Is there any progress on this issue?

Expanding on the original issue, it would be useful to be able to specify this both a global default as well as a per-option setting. In most cases I would expect string options to be only passed once and having to specify this every time would be excessive. But for some options it makes sense to allow multiple values and array type conflicts with trailing arguments, so the "duplicates" behaviour is exactly what I would want there.

@laggingreflex
Copy link
Contributor

laggingreflex commented Nov 12, 2016

@bcoe I'm trying to add this feature through yargs-parser, checkout this pr, but I'm not sure about where this config should be specified from. With the current PR it would require one to put {"yargs": {"duplicate-arguments-array": false}} in their package.json due to how yargs passes "configuration" to yargs-parser. Please review it and suggest a better way if possible..

@laggingreflex
Copy link
Contributor

This has been added

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

No branches or pull requests

4 participants