minimistjs / minimist

parse argument options
MIT License
515 stars 30 forks source link

Special handling of boolean long option value does not work for alias #30

Closed shadowspawn closed 1 year ago

shadowspawn commented 1 year ago

The special case handling of a string value embedded with a boolean long option does not take into account aliases. There is a simple coercion to treat the string as a boolean by testing against 'false'. (So fairly niche, and not documented in README.)

Found by code inspection, not from usage.

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

const minimist = require('minimist');

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

console.log(result);
% node prob1.js                
{ _: [], a: false, aa: false, bb: false, b: false }

% node prob1.js --aa=false --bb=false
{ _: [], a: 'false', aa: 'false', bb: false, b: false }

% node prob1.js --aa=A --bb=B  
{ _: [], a: 'A', aa: 'A', bb: true, b: true }