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

type "array" with "duplicate-arguments-array" works inconsistently #162

Closed
juergba opened this issue Mar 21, 2019 · 1 comment
Closed

type "array" with "duplicate-arguments-array" works inconsistently #162

juergba opened this issue Mar 21, 2019 · 1 comment

Comments

@juergba
Copy link
Contributor

juergba commented Mar 21, 2019

array of type number is not affected by duplicate-arguments-array and doesn't reduce duplicated arguments:

var args = parse(
    ['--file', '2', '--file', '6', '--timeout', '2s', '--timeout', '800'], {
        array: [{key: 'file', number: true}],
        string: ['timeout'],
        configuration: {
            'duplicate-arguments-array': false
        }
});
console.log(args);         // { _: [], file: [ 2, 6 ], timeout: '800' }

array of type string does reduce duplicated arguments with duplicate-arguments-array:

var args = parse(
    ['--file', '2', '--file', '6', '--timeout', '2s', '--timeout', '800'], {
        array: [{key: 'file', string: true}],
        string: ['timeout'],
        configuration: {
            'duplicate-arguments-array': false
        }
});
console.log(args);         // { _: [], file: [ '6' ], timeout: '800' }

An array of type boolean is always reduced, indepently of duplicate-arguments-array. So it doesn't seem possible to build an array of boolean with more than one element.

It is not clear:

  • wether duplicate-arguments-array should reduce array's at all. Analysing the tests, the answer is yes. Maybe it would be more logical to exclude array's from this rule?
  • the behavior of typed array's is not consistent (number <=> string).
@juergba
Copy link
Contributor Author

juergba commented Jul 31, 2019

With the current master this issue has been fixed:

var args = parse(
    '--nr 2 3 --nr 5 6 --str foo bar --str baz yop --bool true false --bool false true', {
        array: ['nr', 'str', 'bool'],
        number: ['nr'],
        string: ['str'],
        boolean: ['bool'],
        configuration: {
            'duplicate-arguments-array': false
        }
});

output:

{ _: [],
  nr: [ 5, 6 ],
  str: [ 'baz', 'yop' ],
  bool: [ false, true ] }

This issue can be closed.

@juergba juergba closed this as completed 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
Development

Successfully merging a pull request may close this issue.

1 participant