Skip to content

Commit

Permalink
[patch]: test for boolean in setarg should include aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Apr 8, 2023
1 parent 9fe62ea commit c38e4cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module.exports = function (args, opts) {
o = {};
}
if (o === Array.prototype) { o = []; }
if (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {
if (o[lastKey] === undefined || isBooleanKey(lastKey) || typeof o[lastKey] === 'boolean') {
o[lastKey] = value;
} else if (Array.isArray(o[lastKey])) {
o[lastKey].push(value);
Expand Down
17 changes: 17 additions & 0 deletions test/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,20 @@ test('auto bool accumulates with auto string', function (t) {

t.end();
});

test('declared boolean alias overwrites string', function (t) {
// This is very contrived, but test for boolean for overwrite should include aliases.
// https://github.com/minimistjs/minimist/issues/31
var argv = parse(['-b', 'moo'], {
boolean: ['bool'],
default: { bool: 'silly' }, // misuse default to get a string value into a boolean option!
alias: { bool: 'b' },
});

t.deepEqual(argv, {
bool: true, b: true,
_: ['moo'],
});

t.end();
});

0 comments on commit c38e4cf

Please sign in to comment.