Permalink
Browse files

nonval options cannot have default values

  • Loading branch information...
shinout committed Apr 7, 2012
1 parent cb3b643 commit fd0813aa2885e2d9708d33b688ea83394e2dbf00
Showing with 13 additions and 1 deletion.
  1. +5 −0 ArgParser.js
  2. +1 −1 package.json
  3. +7 −0 test/test.js
View
@@ -105,6 +105,11 @@ ArgParser.prototype.defaults = function(obj, noSetNums) {
var nums = [];
keys.forEach(function(k) {
var val = obj[k];
+ var s_l = (k.length == 1) ? 's' : 'l';
+ if (this._opts[s_l].indexOf(k) >= 0) {
+ throw new Error("nonvals options cannot have default value.");
+ }
+
if (typeof val == "number") nums.push(k);
this._defaults[k] = val;
}, this);
View
@@ -1,6 +1,6 @@
{
"name": "argparser"
-, "version": "0.2.1"
+, "version": "0.2.2"
, "description": "object to parse commandline-args and options."
, "keywords": ["getopt", "arguments", "option", "getopts", "command"]
, "author": "SHIN Suzuki <shinout310@gmail.com>"
View
@@ -117,6 +117,13 @@ test("strictEqual", parser.opt("hoge"), 14);
parser.parse(["--hoge", "13"]);
test("strictEqual", parser.opt("hoge"), 13);
test('result', 'default test');
+try {
+ parser = ArgParser.nonvals("s").defaults({ "s" : 14 });
+ test("ng");
+}
+catch (e) {
+ test("ok", e.message.match("cannot have default"));
+}
// ap shortcut creating

0 comments on commit fd0813a

Please sign in to comment.