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

Fix: boolean[] - eatArray() with boolean typed arrays and user defaults #185

Merged
merged 2 commits into from
Jul 30, 2019

Conversation

juergba
Copy link
Contributor

@juergba juergba commented Jun 25, 2019

Description

var args = parse('--file --file', {
    array: ['file'],
    boolean: ['file'],
    configuration: {
      'duplicate-arguments-array': true,
      'flatten-duplicate-arrays': false
    }
})      // { _: [], file: [ [], [], [] ] }

The result is incorrect, it should be: { _: [], file: [ [true], [true] ] }

Description of Change

  • eatArray() is called even for flags without arguments. This enables to set:
    • boolean with short syntax ('--bool --bool') which carries its implicit value true
    • default values given by opts.default for all type of options (except boolean)
  • the fallback default value for all type of options is an empty array [].
  • eatArray(): remove the multipleArrayFlag logic. The "duplicate array" pattern is already handled within setKey() depending on the flatten-duplicate-arrays configuration option. setKey() remains unchanged.

@juergba juergba force-pushed the issue/boolean-array branch 2 times, most recently from d1cdc70 to dfc3b32 Compare July 13, 2019 17:11
@bcoe
Copy link
Member

bcoe commented Jul 13, 2019

@juergba this is looking like a reasonable start to me, looks like there's an outstanding TODO?

@juergba juergba force-pushed the issue/boolean-array branch 2 times, most recently from 7096618 to 2f2ff5a Compare July 25, 2019 12:17
@juergba juergba changed the title Fix: boolean[] - eatArray() with boolean typed arrays Fix: boolean[] - eatArray() with boolean typed arrays and user defaults Jul 25, 2019
@bcoe
Copy link
Member

bcoe commented Jul 29, 2019

@juergba 👋 just following up, would love to see this over the finish line.

@juergba juergba marked this pull request as ready for review July 29, 2019 07:17
@bcoe bcoe merged commit 7d42572 into yargs:master Jul 30, 2019
@bcoe
Copy link
Member

bcoe commented Jul 30, 2019

@juergba thank you, this looks great.

This was referenced Mar 13, 2021
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.

2 participants