Refactoring day1
This commit is contained in:
32
node_modules/nopt/LICENSE
generated
vendored
32
node_modules/nopt/LICENSE
generated
vendored
@@ -1,15 +1,23 @@
|
||||
The ISC License
|
||||
Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
|
||||
All rights reserved.
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
87
node_modules/nopt/README.md
generated
vendored
87
node_modules/nopt/README.md
generated
vendored
@@ -5,10 +5,9 @@ The Wrong Way is to sit down and write an option parser. We've all done
|
||||
that.
|
||||
|
||||
The Right Way is to write some complex configurable program with so many
|
||||
options that you hit the limit of your frustration just trying to
|
||||
manage them all, and defer it with duct-tape solutions until you see
|
||||
exactly to the core of the problem, and finally snap and write an
|
||||
awesome option parser.
|
||||
options that you go half-insane just trying to manage them all, and put
|
||||
it off with duct-tape solutions until you see exactly to the core of the
|
||||
problem, and finally snap and write an awesome option parser.
|
||||
|
||||
If you want to write an option parser, don't write an option parser.
|
||||
Write a package manager, or a source control system, or a service
|
||||
@@ -19,37 +18,34 @@ nice option parser.
|
||||
|
||||
## USAGE
|
||||
|
||||
```javascript
|
||||
// my-program.js
|
||||
var nopt = require("nopt")
|
||||
, Stream = require("stream").Stream
|
||||
, path = require("path")
|
||||
, knownOpts = { "foo" : [String, null]
|
||||
, "bar" : [Stream, Number]
|
||||
, "baz" : path
|
||||
, "bloo" : [ "big", "medium", "small" ]
|
||||
, "flag" : Boolean
|
||||
, "pick" : Boolean
|
||||
, "many1" : [String, Array]
|
||||
, "many2" : [path, Array]
|
||||
}
|
||||
, shortHands = { "foofoo" : ["--foo", "Mr. Foo"]
|
||||
, "b7" : ["--bar", "7"]
|
||||
, "m" : ["--bloo", "medium"]
|
||||
, "p" : ["--pick"]
|
||||
, "f" : ["--flag"]
|
||||
}
|
||||
// everything is optional.
|
||||
// knownOpts and shorthands default to {}
|
||||
// arg list defaults to process.argv
|
||||
// slice defaults to 2
|
||||
, parsed = nopt(knownOpts, shortHands, process.argv, 2)
|
||||
console.log(parsed)
|
||||
```
|
||||
// my-program.js
|
||||
var nopt = require("nopt")
|
||||
, Stream = require("stream").Stream
|
||||
, path = require("path")
|
||||
, knownOpts = { "foo" : [String, null]
|
||||
, "bar" : [Stream, Number]
|
||||
, "baz" : path
|
||||
, "bloo" : [ "big", "medium", "small" ]
|
||||
, "flag" : Boolean
|
||||
, "pick" : Boolean
|
||||
, "many" : [String, Array]
|
||||
}
|
||||
, shortHands = { "foofoo" : ["--foo", "Mr. Foo"]
|
||||
, "b7" : ["--bar", "7"]
|
||||
, "m" : ["--bloo", "medium"]
|
||||
, "p" : ["--pick"]
|
||||
, "f" : ["--flag"]
|
||||
}
|
||||
// everything is optional.
|
||||
// knownOpts and shorthands default to {}
|
||||
// arg list defaults to process.argv
|
||||
// slice defaults to 2
|
||||
, parsed = nopt(knownOpts, shortHands, process.argv, 2)
|
||||
console.log(parsed)
|
||||
|
||||
This would give you support for any of the following:
|
||||
|
||||
```console
|
||||
```bash
|
||||
$ node my-program.js --foo "blerp" --no-flag
|
||||
{ "foo" : "blerp", "flag" : false }
|
||||
|
||||
@@ -65,12 +61,12 @@ $ node my-program.js -fp --foofoo
|
||||
$ node my-program.js --foofoo -- -fp # -- stops the flag parsing.
|
||||
{ foo: "Mr. Foo", argv: { remain: ["-fp"] } }
|
||||
|
||||
$ 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
|
||||
$ node my-program.js --blatzk 1000 -fp # unknown opts are ok.
|
||||
{ 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-"
|
||||
{ blatzk: false, flag: true, pick: true }
|
||||
|
||||
@@ -81,11 +77,11 @@ $ node my-program.js --baz b/a/z # known paths are resolved.
|
||||
# values, and will always be an array. The other types provided
|
||||
# specify what types are allowed in the list.
|
||||
|
||||
$ node my-program.js --many1 5 --many1 null --many1 foo
|
||||
{ many1: ["5", "null", "foo"] }
|
||||
$ node my-program.js --many 1 --many null --many foo
|
||||
{ many: ["1", "null", "foo"] }
|
||||
|
||||
$ node my-program.js --many2 foo --many2 bar
|
||||
{ many2: ["/path/to/foo", "path/to/bar"] }
|
||||
$ node my-program.js --many foo
|
||||
{ many: ["foo"] }
|
||||
```
|
||||
|
||||
Read the tests at the bottom of `lib/nopt.js` for more examples of
|
||||
@@ -120,13 +116,12 @@ considered valid values. For instance, in the example above, the
|
||||
and any other value will be rejected.
|
||||
|
||||
When parsing unknown fields, `"true"`, `"false"`, and `"null"` will be
|
||||
interpreted as their JavaScript equivalents.
|
||||
interpreted as their JavaScript equivalents, and numeric values will be
|
||||
interpreted as a number.
|
||||
|
||||
You can also mix types and values, or multiple types, in a list. For
|
||||
instance `{ blah: [Number, null] }` would allow a value to be set to
|
||||
either a Number or null. When types are ordered, this implies a
|
||||
preference, and the first type that can be used to properly interpret
|
||||
the value will be used.
|
||||
either a Number or null.
|
||||
|
||||
To define a new type, add it to `nopt.typeDefs`. Each item in that
|
||||
hash is an object with a `type` member and a `validate` method. The
|
||||
@@ -141,8 +136,8 @@ config object and remove its invalid properties.
|
||||
|
||||
## Error Handling
|
||||
|
||||
By default, nopt outputs a warning to standard error when invalid values for
|
||||
known options are found. You can change this behavior by assigning a method
|
||||
By default, nopt outputs a warning to standard error when invalid
|
||||
options are found. You can change this behavior by assigning a method
|
||||
to `nopt.invalidHandler`. This method will be called with
|
||||
the offending `nopt.invalidHandler(key, val, types)`.
|
||||
|
||||
|
||||
14
node_modules/nopt/bin/nopt.js
generated
vendored
14
node_modules/nopt/bin/nopt.js
generated
vendored
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
var nopt = require("../lib/nopt")
|
||||
, path = require("path")
|
||||
, types = { num: Number
|
||||
, bool: Boolean
|
||||
, help: Boolean
|
||||
@@ -8,12 +7,7 @@ var nopt = require("../lib/nopt")
|
||||
, "num-list": [Number, Array]
|
||||
, "str-list": [String, Array]
|
||||
, "bool-list": [Boolean, Array]
|
||||
, str: String
|
||||
, clear: Boolean
|
||||
, config: Boolean
|
||||
, length: Number
|
||||
, file: path
|
||||
}
|
||||
, str: String }
|
||||
, shorthands = { s: [ "--str", "astring" ]
|
||||
, b: [ "--bool" ]
|
||||
, nb: [ "--no-bool" ]
|
||||
@@ -21,11 +15,7 @@ var nopt = require("../lib/nopt")
|
||||
, "?": ["--help"]
|
||||
, h: ["--help"]
|
||||
, H: ["--help"]
|
||||
, n: [ "--num", "125" ]
|
||||
, c: ["--config"]
|
||||
, l: ["--length"]
|
||||
, f: ["--file"]
|
||||
}
|
||||
, n: [ "--num", "125" ] }
|
||||
, parsed = nopt( types
|
||||
, shorthands
|
||||
, process.argv
|
||||
|
||||
361
node_modules/nopt/lib/nopt.js
generated
vendored
361
node_modules/nopt/lib/nopt.js
generated
vendored
@@ -8,7 +8,6 @@ var url = require("url")
|
||||
, path = require("path")
|
||||
, Stream = require("stream").Stream
|
||||
, abbrev = require("abbrev")
|
||||
, osenv = require("osenv")
|
||||
|
||||
module.exports = exports = nopt
|
||||
exports.clean = clean
|
||||
@@ -34,26 +33,24 @@ function nopt (types, shorthands, args, slice) {
|
||||
args = args.slice(slice)
|
||||
var data = {}
|
||||
, key
|
||||
, argv = {
|
||||
remain: [],
|
||||
cooked: args,
|
||||
original: args.slice(0)
|
||||
}
|
||||
, remain = []
|
||||
, cooked = args
|
||||
, original = args.slice(0)
|
||||
|
||||
parse(args, data, argv.remain, types, shorthands)
|
||||
parse(args, data, remain, types, shorthands)
|
||||
// now data is full
|
||||
clean(data, types, exports.typeDefs)
|
||||
data.argv = argv
|
||||
Object.defineProperty(data.argv, 'toString', { value: function () {
|
||||
data.argv = {remain:remain,cooked:cooked,original:original}
|
||||
data.argv.toString = function () {
|
||||
return this.original.map(JSON.stringify).join(" ")
|
||||
}, enumerable: false })
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
function clean (data, types, typeDefs) {
|
||||
typeDefs = typeDefs || exports.typeDefs
|
||||
var remove = {}
|
||||
, typeDefault = [false, true, null, String, Array]
|
||||
, typeDefault = [false, true, null, String, Number]
|
||||
|
||||
Object.keys(data).forEach(function (k) {
|
||||
if (k === "argv") return
|
||||
@@ -113,12 +110,7 @@ function clean (data, types, typeDefs) {
|
||||
return d[k]
|
||||
}).filter(function (val) { return val !== remove })
|
||||
|
||||
// if we allow Array specifically, then an empty array is how we
|
||||
// express 'no value here', not null. Allow it.
|
||||
if (!val.length && type.indexOf(Array) === -1) {
|
||||
debug('VAL HAS NO LENGTH, DELETE IT', val, k, type.indexOf(Array))
|
||||
delete data[k]
|
||||
}
|
||||
if (!val.length) delete data[k]
|
||||
else if (isArray) {
|
||||
debug(isArray, data[k], val)
|
||||
data[k] = val
|
||||
@@ -133,20 +125,7 @@ function validateString (data, k, val) {
|
||||
}
|
||||
|
||||
function validatePath (data, k, val) {
|
||||
if (val === true) return false
|
||||
if (val === null) return true
|
||||
|
||||
val = String(val)
|
||||
|
||||
var isWin = process.platform === 'win32'
|
||||
, homePattern = isWin ? /^~(\/|\\)/ : /^~\//
|
||||
, home = osenv.home()
|
||||
|
||||
if (home && val.match(homePattern)) {
|
||||
data[k] = path.resolve(home, val.substr(2))
|
||||
} else {
|
||||
data[k] = path.resolve(val)
|
||||
}
|
||||
data[k] = path.resolve(String(val))
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -157,8 +136,8 @@ function validateNumber (data, k, val) {
|
||||
}
|
||||
|
||||
function validateDate (data, k, val) {
|
||||
debug("validate Date %j %j %j", k, val, Date.parse(val))
|
||||
var s = Date.parse(val)
|
||||
debug("validate Date %j %j %j", k, val, s)
|
||||
if (isNaN(s)) return false
|
||||
data[k] = new Date(val)
|
||||
}
|
||||
@@ -220,8 +199,7 @@ function validate (data, k, val, type, typeDefs) {
|
||||
for (var i = 0, l = types.length; i < l; i ++) {
|
||||
debug("test type %j %j %j", k, val, types[i])
|
||||
var t = typeDefs[types[i]]
|
||||
if (t &&
|
||||
((type && type.name && t.type && t.type.name) ? (type.name === t.type.name) : (type === t.type))) {
|
||||
if (t && type === t.type) {
|
||||
var d = {}
|
||||
ok = false !== t.validate(d, k, val)
|
||||
val = d[k]
|
||||
@@ -257,16 +235,13 @@ function parse (args, data, remain, types, shorthands) {
|
||||
args[i] = "--"
|
||||
break
|
||||
}
|
||||
var hadEq = false
|
||||
if (arg.charAt(0) === "-" && arg.length > 1) {
|
||||
var at = arg.indexOf('=')
|
||||
if (at > -1) {
|
||||
hadEq = true
|
||||
var v = arg.substr(at + 1)
|
||||
arg = arg.substr(0, at)
|
||||
args.splice(i, 1, arg, v)
|
||||
if (arg.charAt(0) === "-") {
|
||||
if (arg.indexOf("=") !== -1) {
|
||||
var v = arg.split("=")
|
||||
arg = v.shift()
|
||||
v = v.join("=")
|
||||
args.splice.apply(args, [i, 1].concat([arg, v]))
|
||||
}
|
||||
|
||||
// see if it's a shorthand
|
||||
// if so, splice and back up to re-parse it.
|
||||
var shRes = resolveShort(arg, shorthands, shortAbbr, abbrevs)
|
||||
@@ -280,7 +255,7 @@ function parse (args, data, remain, types, shorthands) {
|
||||
}
|
||||
}
|
||||
arg = arg.replace(/^-+/, "")
|
||||
var no = null
|
||||
var no = false
|
||||
while (arg.toLowerCase().indexOf("no-") === 0) {
|
||||
no = !no
|
||||
arg = arg.substr(3)
|
||||
@@ -288,33 +263,18 @@ function parse (args, data, remain, types, shorthands) {
|
||||
|
||||
if (abbrevs[arg]) arg = abbrevs[arg]
|
||||
|
||||
var argType = types[arg]
|
||||
var isTypeArray = Array.isArray(argType)
|
||||
if (isTypeArray && argType.length === 1) {
|
||||
isTypeArray = false
|
||||
argType = argType[0]
|
||||
}
|
||||
|
||||
var isArray = argType === Array ||
|
||||
isTypeArray && argType.indexOf(Array) !== -1
|
||||
|
||||
// allow unknown things to be arrays if specified multiple times.
|
||||
if (!types.hasOwnProperty(arg) && data.hasOwnProperty(arg)) {
|
||||
if (!Array.isArray(data[arg]))
|
||||
data[arg] = [data[arg]]
|
||||
isArray = true
|
||||
}
|
||||
var isArray = types[arg] === Array ||
|
||||
Array.isArray(types[arg]) && types[arg].indexOf(Array) !== -1
|
||||
|
||||
var val
|
||||
, la = args[i + 1]
|
||||
|
||||
var isBool = typeof no === 'boolean' ||
|
||||
argType === Boolean ||
|
||||
isTypeArray && argType.indexOf(Boolean) !== -1 ||
|
||||
(typeof argType === 'undefined' && !hadEq) ||
|
||||
var isBool = no ||
|
||||
types[arg] === Boolean ||
|
||||
Array.isArray(types[arg]) && types[arg].indexOf(Boolean) !== -1 ||
|
||||
(la === "false" &&
|
||||
(argType === null ||
|
||||
isTypeArray && ~argType.indexOf(null)))
|
||||
(types[arg] === null ||
|
||||
Array.isArray(types[arg]) && ~types[arg].indexOf(null)))
|
||||
|
||||
if (isBool) {
|
||||
// just set and move along
|
||||
@@ -328,22 +288,22 @@ function parse (args, data, remain, types, shorthands) {
|
||||
}
|
||||
|
||||
// also support "foo":[Boolean, "bar"] and "--foo bar"
|
||||
if (isTypeArray && la) {
|
||||
if (~argType.indexOf(la)) {
|
||||
if (Array.isArray(types[arg]) && la) {
|
||||
if (~types[arg].indexOf(la)) {
|
||||
// an explicit type
|
||||
val = la
|
||||
i ++
|
||||
} else if ( la === "null" && ~argType.indexOf(null) ) {
|
||||
} else if ( la === "null" && ~types[arg].indexOf(null) ) {
|
||||
// null allowed
|
||||
val = null
|
||||
i ++
|
||||
} else if ( !la.match(/^-{2,}[^-]/) &&
|
||||
!isNaN(la) &&
|
||||
~argType.indexOf(Number) ) {
|
||||
~types[arg].indexOf(Number) ) {
|
||||
// number
|
||||
val = +la
|
||||
i ++
|
||||
} else if ( !la.match(/^-[^-]/) && ~argType.indexOf(String) ) {
|
||||
} else if ( !la.match(/^-[^-]/) && ~types[arg].indexOf(String) ) {
|
||||
// string
|
||||
val = la
|
||||
i ++
|
||||
@@ -356,15 +316,6 @@ function parse (args, data, remain, types, shorthands) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (argType === String) {
|
||||
if (la === undefined) {
|
||||
la = ""
|
||||
} else if (la.match(/^-{1,2}[^-]+/)) {
|
||||
la = ""
|
||||
i --
|
||||
}
|
||||
}
|
||||
|
||||
if (la && la.match(/^-{2,}$/)) {
|
||||
la = undefined
|
||||
i --
|
||||
@@ -387,55 +338,215 @@ function resolveShort (arg, shorthands, shortAbbr, abbrevs) {
|
||||
// all of the chars are single-char shorthands, and it's
|
||||
// not a match to some other abbrev.
|
||||
arg = arg.replace(/^-+/, '')
|
||||
|
||||
// if it's an exact known option, then don't go any further
|
||||
if (abbrevs[arg] === arg)
|
||||
if (abbrevs[arg] && !shorthands[arg]) {
|
||||
return null
|
||||
|
||||
// if it's an exact known shortopt, same deal
|
||||
if (shorthands[arg]) {
|
||||
// make it an array, if it's a list of words
|
||||
if (shorthands[arg] && !Array.isArray(shorthands[arg]))
|
||||
shorthands[arg] = shorthands[arg].split(/\s+/)
|
||||
|
||||
return shorthands[arg]
|
||||
}
|
||||
|
||||
// first check to see if this arg is a set of single-char shorthands
|
||||
var singles = shorthands.___singles
|
||||
if (!singles) {
|
||||
singles = Object.keys(shorthands).filter(function (s) {
|
||||
return s.length === 1
|
||||
}).reduce(function (l,r) {
|
||||
l[r] = true
|
||||
return l
|
||||
}, {})
|
||||
shorthands.___singles = singles
|
||||
debug('shorthand singles', singles)
|
||||
}
|
||||
|
||||
var chrs = arg.split("").filter(function (c) {
|
||||
return singles[c]
|
||||
})
|
||||
|
||||
if (chrs.join("") === arg) return chrs.map(function (c) {
|
||||
return shorthands[c]
|
||||
}).reduce(function (l, r) {
|
||||
return l.concat(r)
|
||||
}, [])
|
||||
|
||||
|
||||
// if it's an arg abbrev, and not a literal shorthand, then prefer the arg
|
||||
if (abbrevs[arg] && !shorthands[arg])
|
||||
return null
|
||||
|
||||
// if it's an abbr for a shorthand, then use that
|
||||
if (shortAbbr[arg])
|
||||
if (shortAbbr[arg]) {
|
||||
arg = shortAbbr[arg]
|
||||
} else {
|
||||
var singles = shorthands.___singles
|
||||
if (!singles) {
|
||||
singles = Object.keys(shorthands).filter(function (s) {
|
||||
return s.length === 1
|
||||
}).reduce(function (l,r) { l[r] = true ; return l }, {})
|
||||
shorthands.___singles = singles
|
||||
}
|
||||
var chrs = arg.split("").filter(function (c) {
|
||||
return singles[c]
|
||||
})
|
||||
if (chrs.join("") === arg) return chrs.map(function (c) {
|
||||
return shorthands[c]
|
||||
}).reduce(function (l, r) {
|
||||
return l.concat(r)
|
||||
}, [])
|
||||
}
|
||||
|
||||
// make it an array, if it's a list of words
|
||||
if (shorthands[arg] && !Array.isArray(shorthands[arg]))
|
||||
if (shorthands[arg] && !Array.isArray(shorthands[arg])) {
|
||||
shorthands[arg] = shorthands[arg].split(/\s+/)
|
||||
|
||||
}
|
||||
return shorthands[arg]
|
||||
}
|
||||
|
||||
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")}
|
||||
,[]]
|
||||
].forEach(function (test) {
|
||||
var argv = test[0].split(/\s+/)
|
||||
, opts = test[1]
|
||||
, rem = test[2]
|
||||
, actual = nopt(types, 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)
|
||||
})
|
||||
}
|
||||
|
||||
46
node_modules/nopt/package.json
generated
vendored
46
node_modules/nopt/package.json
generated
vendored
@@ -1,30 +1,16 @@
|
||||
{
|
||||
"name": "nopt",
|
||||
"version": "4.0.3",
|
||||
"description": "Option parsing for Node, supporting types, shorthands, etc. Used by npm.",
|
||||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
||||
"main": "lib/nopt.js",
|
||||
"scripts": {
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"prepublishOnly": "git push origin --follow-tags",
|
||||
"test": "tap test/*.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/npm/nopt.git"
|
||||
},
|
||||
"bin": "./bin/nopt.js",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"abbrev": "1",
|
||||
"osenv": "^0.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^14.10.6"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"lib"
|
||||
]
|
||||
}
|
||||
{ "name" : "nopt"
|
||||
, "version" : "1.0.10"
|
||||
, "description" : "Option parsing for Node, supporting types, shorthands, etc. Used by npm."
|
||||
, "author" : "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)"
|
||||
, "main" : "lib/nopt.js"
|
||||
, "scripts" : { "test" : "node lib/nopt.js" }
|
||||
, "repository" : "http://github.com/isaacs/nopt"
|
||||
, "bin" : "./bin/nopt.js"
|
||||
, "license" :
|
||||
{ "type" : "MIT"
|
||||
, "url" : "https://github.com/isaacs/nopt/raw/master/LICENSE" }
|
||||
, "dependencies" : { "abbrev" : "1" }
|
||||
,"_resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz"
|
||||
,"_integrity": "sha1-bd0hvSoxQXuScn3Vhfim83YI6+4="
|
||||
,"_from": "nopt@1.0.10"
|
||||
}
|
||||
Reference in New Issue
Block a user