From 1ab743bad4484d69f1259bed42f9531de01119de Mon Sep 17 00:00:00 2001 From: Trevor Senior Date: Wed, 30 Apr 2014 18:06:05 -0400 Subject: [PATCH] aliased values treated as strings --- index.js | 13 ++++++++----- test/parse.js | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index d181233..71fb830 100644 --- a/index.js +++ b/index.js @@ -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]); @@ -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 = { _ : [] }; diff --git a/test/parse.js b/test/parse.js index 8a90646..319e683 100644 --- a/test/parse.js +++ b/test/parse.js @@ -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' ]),