diff --git a/index.js b/index.js index 78cafa8..389285f 100644 --- a/index.js +++ b/index.js @@ -89,7 +89,9 @@ module.exports = function (args, opts) { for (var i = 0; i < keys.length - 1; i++) { var key = keys[i]; if (isConstructorOrProto(o, key)) { return; } - if (o[key] === undefined) { o[key] = {}; } + if (o[key] === undefined) { + o[key] = (/^\d+$/).test(keys[i + 1]) ? [] : {}; + } if ( o[key] === Object.prototype || o[key] === Number.prototype diff --git a/test/dotted.js b/test/dotted.js index c606118..ac524c1 100644 --- a/test/dotted.js +++ b/test/dotted.js @@ -25,12 +25,8 @@ test('dotted default with no alias', function (t) { test('dotted array', function (t) { var argv = parse(['--a.1.foo', '11']); - - t.notOk(Array.isArray(argv.a)); - - t.notOk(0 in argv.a); - + t.true(Array.isArray(argv.a)); + t.false(0 in argv.a); t.equal(argv.a[1].foo, 11); - t.end(); });