Permalink
Browse files

In narwhal/args, changed Parser.reset() to ensure

that the options hash doesn't already have a
value for the state and also added a type check.

In Parser.parse(), switched to Parser.reset()
instead of manually resetting the hash.
  • Loading branch information...
1 parent 2ca38c4 commit b39f41dd685527664259e3f2dc2a6dc8a1812fcc @abhinav abhinav committed Aug 8, 2010
Showing with 6 additions and 12 deletions.
  1. +6 −12 packages/narwhal-lib/lib/narwhal/args.js
View
18 packages/narwhal-lib/lib/narwhal/args.js
@@ -53,11 +53,14 @@ exports.Parser.prototype.def = function (name, value) {
exports.Parser.prototype.reset = function (options) {
for (var name in this._def) {
- if (util.has(this._def, name))
+ if (util.has(this._def, name) && !util.has(options, name))
options[name] = util.copy(this._def[name]);
}
this._options.forEach(function (option) {
- options[option.getName()] = option._def;
+ if (!(option instanceof self.Option))
+ return;
+ if (!util.has(options, option.getName()))
+ options[option.getName()] = option._def;
});
};
@@ -379,16 +382,7 @@ exports.Parser.prototype.parse = function (args, options, noCommand, allowInterl
};
// initial values
- for (var name in this._def) {
- if (util.has(this._def, name) && !util.has(options, name))
- options[name] = util.copy(this._def[name]);
- }
- this._options.forEach(function (option) {
- if (!(option instanceof self.Option))
- return;
- if (!util.has(options, option.getName()))
- options[option.getName()] = option._def;
- });
+ this.reset(options);
var interleavedArgs = [];

0 comments on commit b39f41d

Please sign in to comment.