Skip to content

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

Closed

Description

@juergba

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).

Activity

  1. juergba commented on Jul 31, 2019

    @juergba
    ContributorAuthor

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions