Skip to content

Commit

Permalink
fix: ensure default types cascade to alibi;
Browse files Browse the repository at this point in the history
- Closes #10
  • Loading branch information
lukeed committed Mar 24, 2020
1 parent 40051e6 commit 5437ea5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ module.exports = function (args, opts) {

if (defaults) {
for (k in opts.default) {
opts.alias[k] = opts.alias[k] || [];
(opts[typeof opts.default[k]] || []).push(k);
name = typeof opts.default[k];
arr = opts.alias[k] = opts.alias[k] || [];
if (opts[name] !== void 0) {
opts[name].push(k);
for (i=0; i < arr.length; i++) {
opts[name].push(arr[i]);
}
}
}
}

Expand Down
48 changes: 48 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,54 @@ test('flag default and alias', t => {
t.end();
});

test('flag default string w/ alias', t => {
t.deepEqual(
fn(['--arg', '01'], {
alias: { a: ['arg'] },
default: { arg: '' },
}),
{ _: [], arg: '01', a: '01' }
);

t.deepEqual(
fn(['-a', '01'], {
alias: { a: ['arg'] },
default: { arg: '' },
}),
{ _: [], arg: '01', a: '01' }
);

// ---

t.deepEqual(
fn(['-a', '01'], {
alias: { arg: ['a'] },
default: { a: '' },
}),
{ _: [], arg: '01', a: '01' }
);

t.deepEqual(
fn(['--arg', '01'], {
alias: { arg: ['a'] },
default: { a: '' },
}),
{ _: [], arg: '01', a: '01' }
);

// ---

t.deepEqual(
fn(['-a', '01'], {
alias: { arg: ['a'] },
default: { arg: '' },
}),
{ _: [], arg: '01', a: '01' }
);

t.end();
});

// test('newlines in params' , t => {
// var args = fn(['-s', "X\nX"])
// t.deepEqual(args, { _ : [], s : "X\nX" });
Expand Down

0 comments on commit 5437ea5

Please sign in to comment.