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 Jul 13, 2019
@bcoe
Copy link
Member

@bcoe 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 from dfc3b32 to 29542b2 Jul 14, 2019
@juergba juergba force-pushed the issue/boolean-array branch 2 times, most recently from 7096618 to 2f2ff5a Jul 25, 2019
@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 bcoe commented Jul 29, 2019

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

@juergba juergba force-pushed the issue/boolean-array branch from 664a621 to 18da29e Jul 29, 2019
@juergba juergba marked this pull request as ready for review Jul 29, 2019
@bcoe bcoe merged commit 7d42572 into yargs:master Jul 30, 2019
2 checks passed
@bcoe
Copy link
Member

@bcoe bcoe commented Jul 30, 2019

@juergba thank you, this looks great.

@juergba juergba deleted the issue/boolean-array branch Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants