Comparing version 2.1.2 to 2.2.0
213
lib/nopt.js
@@ -128,2 +128,3 @@ // info about each config option. | ||
function validatePath (data, k, val) { | ||
if (val === true) return false | ||
data[k] = path.resolve(String(val)) | ||
@@ -331,2 +332,5 @@ return true | ||
if (types[arg] === String && la === undefined) | ||
la = "" | ||
if (la && la.match(/^-{2,}$/)) { | ||
@@ -406,210 +410,1 @@ la = undefined | ||
} | ||
if (module === require.main) { | ||
var assert = require("assert") | ||
, util = require("util") | ||
, shorthands = | ||
{ s : ["--loglevel", "silent"] | ||
, d : ["--loglevel", "info"] | ||
, dd : ["--loglevel", "verbose"] | ||
, ddd : ["--loglevel", "silly"] | ||
, noreg : ["--no-registry"] | ||
, reg : ["--registry"] | ||
, "no-reg" : ["--no-registry"] | ||
, silent : ["--loglevel", "silent"] | ||
, verbose : ["--loglevel", "verbose"] | ||
, h : ["--usage"] | ||
, H : ["--usage"] | ||
, "?" : ["--usage"] | ||
, help : ["--usage"] | ||
, v : ["--version"] | ||
, f : ["--force"] | ||
, desc : ["--description"] | ||
, "no-desc" : ["--no-description"] | ||
, "local" : ["--no-global"] | ||
, l : ["--long"] | ||
, p : ["--parseable"] | ||
, porcelain : ["--parseable"] | ||
, g : ["--global"] | ||
} | ||
, types = | ||
{ aoa: Array | ||
, nullstream: [null, Stream] | ||
, date: Date | ||
, str: String | ||
, browser : String | ||
, cache : path | ||
, color : ["always", Boolean] | ||
, depth : Number | ||
, description : Boolean | ||
, dev : Boolean | ||
, editor : path | ||
, force : Boolean | ||
, global : Boolean | ||
, globalconfig : path | ||
, group : [String, Number] | ||
, gzipbin : String | ||
, logfd : [Number, Stream] | ||
, loglevel : ["silent","win","error","warn","info","verbose","silly"] | ||
, long : Boolean | ||
, "node-version" : [false, String] | ||
, npaturl : url | ||
, npat : Boolean | ||
, "onload-script" : [false, String] | ||
, outfd : [Number, Stream] | ||
, parseable : Boolean | ||
, pre: Boolean | ||
, prefix: path | ||
, proxy : url | ||
, "rebuild-bundle" : Boolean | ||
, registry : url | ||
, searchopts : String | ||
, searchexclude: [null, String] | ||
, shell : path | ||
, t: [Array, String] | ||
, tag : String | ||
, tar : String | ||
, tmp : path | ||
, "unsafe-perm" : Boolean | ||
, usage : Boolean | ||
, user : String | ||
, username : String | ||
, userconfig : path | ||
, version : Boolean | ||
, viewer: path | ||
, _exit : Boolean | ||
} | ||
; [["-v", {version:true}, []] | ||
,["---v", {version:true}, []] | ||
,["ls -s --no-reg connect -d", | ||
{loglevel:"info",registry:null},["ls","connect"]] | ||
,["ls ---s foo",{loglevel:"silent"},["ls","foo"]] | ||
,["ls --registry blargle", {}, ["ls"]] | ||
,["--no-registry", {registry:null}, []] | ||
,["--no-color true", {color:false}, []] | ||
,["--no-color false", {color:true}, []] | ||
,["--no-color", {color:false}, []] | ||
,["--color false", {color:false}, []] | ||
,["--color --logfd 7", {logfd:7,color:true}, []] | ||
,["--color=true", {color:true}, []] | ||
,["--logfd=10", {logfd:10}, []] | ||
,["--tmp=/tmp -tar=gtar",{tmp:"/tmp",tar:"gtar"},[]] | ||
,["--tmp=tmp -tar=gtar", | ||
{tmp:path.resolve(process.cwd(), "tmp"),tar:"gtar"},[]] | ||
,["--logfd x", {}, []] | ||
,["a -true -- -no-false", {true:true},["a","-no-false"]] | ||
,["a -no-false", {false:false},["a"]] | ||
,["a -no-no-true", {true:true}, ["a"]] | ||
,["a -no-no-no-false", {false:false}, ["a"]] | ||
,["---NO-no-No-no-no-no-nO-no-no"+ | ||
"-No-no-no-no-no-no-no-no-no"+ | ||
"-no-no-no-no-NO-NO-no-no-no-no-no-no"+ | ||
"-no-body-can-do-the-boogaloo-like-I-do" | ||
,{"body-can-do-the-boogaloo-like-I-do":false}, []] | ||
,["we are -no-strangers-to-love "+ | ||
"--you-know=the-rules --and=so-do-i "+ | ||
"---im-thinking-of=a-full-commitment "+ | ||
"--no-you-would-get-this-from-any-other-guy "+ | ||
"--no-gonna-give-you-up "+ | ||
"-no-gonna-let-you-down=true "+ | ||
"--no-no-gonna-run-around false "+ | ||
"--desert-you=false "+ | ||
"--make-you-cry false "+ | ||
"--no-tell-a-lie "+ | ||
"--no-no-and-hurt-you false" | ||
,{"strangers-to-love":false | ||
,"you-know":"the-rules" | ||
,"and":"so-do-i" | ||
,"you-would-get-this-from-any-other-guy":false | ||
,"gonna-give-you-up":false | ||
,"gonna-let-you-down":false | ||
,"gonna-run-around":false | ||
,"desert-you":false | ||
,"make-you-cry":false | ||
,"tell-a-lie":false | ||
,"and-hurt-you":false | ||
},["we", "are"]] | ||
,["-t one -t two -t three" | ||
,{t: ["one", "two", "three"]} | ||
,[]] | ||
,["-t one -t null -t three four five null" | ||
,{t: ["one", "null", "three"]} | ||
,["four", "five", "null"]] | ||
,["-t foo" | ||
,{t:["foo"]} | ||
,[]] | ||
,["--no-t" | ||
,{t:["false"]} | ||
,[]] | ||
,["-no-no-t" | ||
,{t:["true"]} | ||
,[]] | ||
,["-aoa one -aoa null -aoa 100" | ||
,{aoa:["one", null, 100]} | ||
,[]] | ||
,["-str 100" | ||
,{str:"100"} | ||
,[]] | ||
,["--color always" | ||
,{color:"always"} | ||
,[]] | ||
,["--no-nullstream" | ||
,{nullstream:null} | ||
,[]] | ||
,["--nullstream false" | ||
,{nullstream:null} | ||
,[]] | ||
,["--notadate=2011-01-25" | ||
,{notadate: "2011-01-25"} | ||
,[]] | ||
,["--date 2011-01-25" | ||
,{date: new Date("2011-01-25")} | ||
,[]] | ||
,["-cl 1" | ||
,{config: true, length: 1} | ||
,[] | ||
,{config: Boolean, length: Number, clear: Boolean} | ||
,{c: "--config", l: "--length"}] | ||
,["--acount bla" | ||
,{"acount":true} | ||
,["bla"] | ||
,{account: Boolean, credentials: Boolean, options: String} | ||
,{a:"--account", c:"--credentials",o:"--options"}] | ||
,["--clear" | ||
,{clear:true} | ||
,[] | ||
,{clear:Boolean,con:Boolean,len:Boolean,exp:Boolean,add:Boolean,rep:Boolean} | ||
,{c:"--con",l:"--len",e:"--exp",a:"--add",r:"--rep"}] | ||
,["--file -" | ||
,{"file":"-"} | ||
,[] | ||
,{file:String} | ||
,{}] | ||
,["--file -" | ||
,{"file":true} | ||
,["-"] | ||
,{file:Boolean} | ||
,{}] | ||
].forEach(function (test) { | ||
var argv = test[0].split(/\s+/) | ||
, opts = test[1] | ||
, rem = test[2] | ||
, actual = nopt(test[3] || types, test[4] || shorthands, argv, 0) | ||
, parsed = actual.argv | ||
delete actual.argv | ||
console.log(util.inspect(actual, false, 2, true), parsed.remain) | ||
for (var i in opts) { | ||
var e = JSON.stringify(opts[i]) | ||
, a = JSON.stringify(actual[i] === undefined ? null : actual[i]) | ||
if (e && typeof e === "object") { | ||
assert.deepEqual(e, a) | ||
} else { | ||
assert.equal(e, a) | ||
} | ||
} | ||
assert.deepEqual(rem, parsed.remain) | ||
}) | ||
} |
{ | ||
"name": "nopt", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "Option parsing for Node, supporting types, shorthands, etc. Used by npm.", | ||
@@ -8,3 +8,3 @@ "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", | ||
"scripts": { | ||
"test": "node lib/nopt.js" | ||
"test": "tap test/*.js" | ||
}, | ||
@@ -19,3 +19,6 @@ "repository": "http://github.com/isaacs/nopt", | ||
"abbrev": "1" | ||
}, | ||
"devDependencies": { | ||
"tap": "~0.4.8" | ||
} | ||
} |
@@ -64,8 +64,8 @@ If you want to write an option parser, and have it be good, there are | ||
$ node my-program.js --blatzk 1000 -fp # unknown opts are ok. | ||
$ node my-program.js --blatzk -fp # unknown opts are ok. | ||
{ blatzk: true, flag: true, pick: true } | ||
$ node my-program.js --blatzk=1000 -fp # but you need to use = if they have a value | ||
{ blatzk: 1000, flag: true, pick: true } | ||
$ node my-program.js --blatzk true -fp # but they need a value | ||
{ blatzk: true, flag: true, pick: true } | ||
$ node my-program.js --no-blatzk -fp # unless they start with "no-" | ||
@@ -72,0 +72,0 @@ { blatzk: false, flag: true, pick: true } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29880
8
651
1