Skip to content

Commit

Permalink
defaults work again, all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed May 14, 2011
1 parent dd87333 commit 89f0d04
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ function Argv (args, cwd) {
return self;
};

var defaults = {};
self.default = function (key, value) {
if (typeof key === 'object') {
Object.keys(key).forEach(function (k) {
self.default(k, key[k]);
defaults[k] = key[k];
});
}
else {
if (self.argv[key] === undefined) {
self.argv[key] = value;
}
defaults[key] = value;
}

return self;
};

Expand Down Expand Up @@ -384,6 +384,12 @@ function Argv (args, cwd) {
}
}

Object.keys(defaults).forEach(function (key) {
if (!(key in argv)) {
argv[key] = defaults[key];
}
});

if (demanded._ && argv._.length < demanded._) {
fail('Not enough non-option arguments: got '
+ argv._.length + ', need at least ' + demanded._
Expand Down

0 comments on commit 89f0d04

Please sign in to comment.