Skip to content

Commit

Permalink
aliased values treated as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor Senior authored and James Halliday committed May 11, 2014
1 parent f0d143e commit 1ab743b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
13 changes: 8 additions & 5 deletions index.js
Expand Up @@ -7,10 +7,6 @@ module.exports = function (args, opts) {
flags.bools[key] = true;
});

[].concat(opts.string).filter(Boolean).forEach(function (key) {
flags.strings[key] = true;
});

var aliases = {};
Object.keys(opts.alias || {}).forEach(function (key) {
aliases[key] = [].concat(opts.alias[key]);
Expand All @@ -20,7 +16,14 @@ module.exports = function (args, opts) {
}));
});
});


[].concat(opts.string).filter(Boolean).forEach(function (key) {
flags.strings[key] = true;
if (aliases[key]) {
flags.strings[aliases[key]] = true;
}
});

var defaults = opts['default'] || {};

var argv = { _ : [] };
Expand Down
23 changes: 23 additions & 0 deletions test/parse.js
Expand Up @@ -183,6 +183,29 @@ test('empty strings', function(t) {
});


test('string and alias', function(t) {
var x = parse([ '--str', '000123' ], {
string: 's',
alias: { s: 'str' }
});

t.equal(x.str, '000123');
t.equal(typeof x.str, 'string');
t.equal(x.s, '000123');
t.equal(typeof x.s, 'string');

var y = parse([ '-s', '000123' ], {
string: 'str',
alias: { str: 's' }
});

t.equal(y.str, '000123');
t.equal(typeof y.str, 'string');
t.equal(y.s, '000123');
t.equal(typeof y.s, 'string');
t.end();
});

test('slashBreak', function (t) {
t.same(
parse([ '-I/foo/bar/baz' ]),
Expand Down

0 comments on commit 1ab743b

Please sign in to comment.