command-line-args
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -27,2 +27,6 @@ var w = require("wodge"), | ||
function isOption(input){ | ||
return longArg.test(input) || shortArg.test(input); | ||
} | ||
function setOutputValue(option, value){ | ||
@@ -39,15 +43,17 @@ model[option.name] = value; | ||
} else if (argv.length) { | ||
if (typeof option.type === "function"){ | ||
if (option.type === Array){ | ||
setOutputValue(option, spliceWhile(argv, /^\w+/)); | ||
} else { | ||
setOutputValue(option, option.type(argv.shift())); | ||
} | ||
} else { | ||
setOutputValue(option, argv.shift()); | ||
} | ||
} else { | ||
console.error(option); | ||
throw new Error("weird case"); | ||
} | ||
var value; | ||
if (typeof option.type === "function" && option.type === Array){ | ||
value = spliceWhile(argv, /^\w+/); | ||
} else { | ||
if (isOption(argv[0])){ | ||
value = null; | ||
} else { | ||
value = argv.shift(); | ||
value = typeof option.type === "function" ? option.type(value) : value; | ||
} | ||
} | ||
setOutputValue(option, value); | ||
} else { | ||
setOutputValue(option, null); | ||
} | ||
} else { | ||
@@ -54,0 +60,0 @@ throw new Error("Unexpected option: " + optionName); |
{ | ||
"name": "command-line-args", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Parse command line options", | ||
@@ -10,2 +10,13 @@ "repository": "https://github.com/75lb/command-line-args.git", | ||
}, | ||
"keywords": [ | ||
"argv", | ||
"parse", | ||
"argument", | ||
"args", | ||
"option", | ||
"parser", | ||
"parsing", | ||
"cli", | ||
"command" | ||
], | ||
"author": "Lloyd Brookes", | ||
@@ -12,0 +23,0 @@ "devDependencies": { |
@@ -24,1 +24,18 @@ var test = require("tap").test; | ||
}); | ||
test("handles missing option value", function(t){ | ||
var argv = [ "--colour" ]; | ||
t.deepEqual(cliArgs(optionDefinitions).parse(argv), { | ||
colour: null | ||
}); | ||
t.end(); | ||
}); | ||
test("handles missing option value", function(t){ | ||
var argv = [ "--colour", "--number", "2" ]; | ||
t.deepEqual(cliArgs(optionDefinitions).parse(argv), { | ||
colour: null, | ||
number: 2 | ||
}); | ||
t.end(); | ||
}); |
13706
404