minimistjs / minimist

parse argument options
MIT License
515 stars 30 forks source link

Override of array behaviour for boolean option does not work for alias #31

Closed shadowspawn closed 1 year ago

shadowspawn commented 1 year ago

There is a test to determine whether an option value should overwrite the previous value, or be added to an array. The test for a boolean option does not take into account the alias. The failure only shows up if the previous value was not a boolean, so not likely to come up in practice.

Found by code inspection, not from usage.

https://github.com/minimistjs/minimist/blob/093bc85eb9b2a06f0d7fa3f7f1940cd135495abf/index.js#L108

const minimist = require('minimist');

const result = minimist(process.argv.slice(2), {
    boolean: ['a', 'bb'],
    alias: { a: 'aa', bb: 'b' }
});

console.log(result);
% node prob2 -a=A -b=B -a -a -b -b
{
  _: [],
  a: true,
  aa: [ 'A', true, true ],
  bb: true,
  b: [ 'B', true, true ]
}