step-node-agent 3.24.5 → 3.24.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/aws4/aws4.js +1 -1
- package/node_modules/aws4/package.json +7 -3
- package/node_modules/unzip-stream/lib/unzip-stream.js +2 -2
- package/node_modules/unzip-stream/package.json +1 -1
- package/package.json +1 -1
- package/node_modules/abbrev/LICENSE +0 -46
- package/node_modules/abbrev/README.md +0 -23
- package/node_modules/abbrev/abbrev.js +0 -61
- package/node_modules/abbrev/package.json +0 -21
- package/node_modules/aws4/.github/FUNDING.yml +0 -3
- package/node_modules/aws4/.travis.yml +0 -9
- package/node_modules/nopt/.npmignore +0 -0
- package/node_modules/nopt/LICENSE +0 -23
- package/node_modules/nopt/README.md +0 -208
- package/node_modules/nopt/bin/nopt.js +0 -44
- package/node_modules/nopt/examples/my-program.js +0 -30
- package/node_modules/nopt/lib/nopt.js +0 -552
- package/node_modules/nopt/package.json +0 -12
- package/node_modules/unzip-stream/.travis.yml +0 -9
- package/node_modules/unzip-stream/aa.zip +0 -0
- package/node_modules/unzip-stream/test.js +0 -29
- package/node_modules/unzip-stream/testData-golang/crc32-not-streamed.zip +0 -0
- package/node_modules/unzip-stream/testData-golang/dd.zip +0 -0
- package/node_modules/unzip-stream/testData-golang/go-no-datadesc-sig.zip +0 -0
- package/node_modules/unzip-stream/testData-golang/go-with-datadesc-sig.zip +0 -0
- package/node_modules/unzip-stream/testData-golang/readme.zip +0 -0
- package/node_modules/unzip-stream/testData-golang/symlink.zip +0 -0
- package/node_modules/unzip-stream/testData-golang/test-trailing-junk.zip +0 -0
- package/node_modules/unzip-stream/testData-golang/test.zip +0 -0
- package/node_modules/unzip-stream/testData-golang/unix.zip +0 -0
- package/node_modules/unzip-stream/testData-golang/winxp.zip +0 -0
- package/node_modules/unzip-stream/testData-golang/zip64-2.zip +0 -0
- package/node_modules/unzip-stream/testData-golang/zip64.zip +0 -0
- package/node_modules/unzip-stream/testData-php/cd-gap.zip +0 -0
- package/node_modules/unzip-stream/testData-php/cd-truncated.zip +0 -0
- package/node_modules/unzip-stream/testData-php/class-trailing-null.zip +0 -0
- package/node_modules/unzip-stream/testData-php/class-trailing-slash.zip +0 -0
- package/node_modules/unzip-stream/testData-php/class.zip +0 -0
- package/node_modules/unzip-stream/testData-php/empty.zip +0 -0
- package/node_modules/unzip-stream/testData-php/looks-like-zip64.zip +0 -0
- package/node_modules/unzip-stream/testData-php/nosig.zip +0 -0
- package/node_modules/unzip-stream/testData-php/split.zip +0 -0
- package/node_modules/unzip-stream/testData-php/trail.zip +0 -0
- package/node_modules/unzip-stream/testData-php/wrong-cd-start-disk.zip +0 -0
- package/node_modules/unzip-stream/testData-php/wrong-central-entry-sig.zip +0 -0
|
@@ -46,7 +46,7 @@ function RequestSigner(request, credentials) {
|
|
|
46
46
|
|
|
47
47
|
if (typeof request === 'string') request = url.parse(request)
|
|
48
48
|
|
|
49
|
-
var headers = request.headers = (request.headers || {}),
|
|
49
|
+
var headers = request.headers = Object.assign({}, (request.headers || {})),
|
|
50
50
|
hostParts = (!this.service || !this.region) && this.matchHost(request.hostname || request.host || headers.Host || headers.host)
|
|
51
51
|
|
|
52
52
|
this.request = request
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aws4",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Signs and prepares requests using AWS Signature Version 4",
|
|
5
5
|
"author": "Michael Hart <michael.hart.au@gmail.com> (https://github.com/mhart)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:mhart/aws4",
|
|
8
8
|
"main": "aws4.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"aws4.js",
|
|
11
|
+
"lru.js"
|
|
12
|
+
],
|
|
9
13
|
"scripts": {
|
|
10
14
|
"test": "mocha ./test/fast.js -R list",
|
|
11
15
|
"integration": "node ./test/slow.js"
|
|
12
16
|
},
|
|
13
17
|
"devDependencies": {
|
|
14
|
-
"mocha": "^
|
|
15
|
-
"should": "^
|
|
18
|
+
"mocha": "^10.4.0",
|
|
19
|
+
"should": "^13.2.3"
|
|
16
20
|
}
|
|
17
21
|
}
|
|
@@ -288,7 +288,7 @@ UnzipStream.prototype._prepareOutStream = function (vars, entry) {
|
|
|
288
288
|
|
|
289
289
|
var isDirectory = vars.uncompressedSize === 0 && /[\/\\]$/.test(entry.path);
|
|
290
290
|
// protect against malicious zip files which want to extract to parent dirs
|
|
291
|
-
entry.path = entry.path.replace(
|
|
291
|
+
entry.path = entry.path.replace(/(?<=^|[/\\]+)[.][.]+(?=[/\\]+|$)/g, ".");
|
|
292
292
|
entry.type = isDirectory ? 'Directory' : 'File';
|
|
293
293
|
entry.isDirectory = isDirectory;
|
|
294
294
|
|
|
@@ -352,7 +352,7 @@ UnzipStream.prototype._prepareOutStream = function (vars, entry) {
|
|
|
352
352
|
|
|
353
353
|
entry.skip = true;
|
|
354
354
|
setImmediate(() => {
|
|
355
|
-
|
|
355
|
+
self.emit('error', new Error(message));
|
|
356
356
|
});
|
|
357
357
|
|
|
358
358
|
// try to skip over this entry
|
package/package.json
CHANGED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
This software is dual-licensed under the ISC and MIT licenses.
|
|
2
|
-
You may use this software under EITHER of the following licenses.
|
|
3
|
-
|
|
4
|
-
----------
|
|
5
|
-
|
|
6
|
-
The ISC License
|
|
7
|
-
|
|
8
|
-
Copyright (c) Isaac Z. Schlueter and Contributors
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
12
|
-
copyright notice and this permission notice appear in all copies.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
15
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
17
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
18
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
19
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
20
|
-
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
21
|
-
|
|
22
|
-
----------
|
|
23
|
-
|
|
24
|
-
Copyright Isaac Z. Schlueter and Contributors
|
|
25
|
-
All rights reserved.
|
|
26
|
-
|
|
27
|
-
Permission is hereby granted, free of charge, to any person
|
|
28
|
-
obtaining a copy of this software and associated documentation
|
|
29
|
-
files (the "Software"), to deal in the Software without
|
|
30
|
-
restriction, including without limitation the rights to use,
|
|
31
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
32
|
-
copies of the Software, and to permit persons to whom the
|
|
33
|
-
Software is furnished to do so, subject to the following
|
|
34
|
-
conditions:
|
|
35
|
-
|
|
36
|
-
The above copyright notice and this permission notice shall be
|
|
37
|
-
included in all copies or substantial portions of the Software.
|
|
38
|
-
|
|
39
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
40
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
41
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
42
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
43
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
44
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
45
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
46
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# abbrev-js
|
|
2
|
-
|
|
3
|
-
Just like [ruby's Abbrev](http://apidock.com/ruby/Abbrev).
|
|
4
|
-
|
|
5
|
-
Usage:
|
|
6
|
-
|
|
7
|
-
var abbrev = require("abbrev");
|
|
8
|
-
abbrev("foo", "fool", "folding", "flop");
|
|
9
|
-
|
|
10
|
-
// returns:
|
|
11
|
-
{ fl: 'flop'
|
|
12
|
-
, flo: 'flop'
|
|
13
|
-
, flop: 'flop'
|
|
14
|
-
, fol: 'folding'
|
|
15
|
-
, fold: 'folding'
|
|
16
|
-
, foldi: 'folding'
|
|
17
|
-
, foldin: 'folding'
|
|
18
|
-
, folding: 'folding'
|
|
19
|
-
, foo: 'foo'
|
|
20
|
-
, fool: 'fool'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
This is handy for command-line scripts, or other cases where you want to be able to accept shorthands.
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
module.exports = exports = abbrev.abbrev = abbrev
|
|
2
|
-
|
|
3
|
-
abbrev.monkeyPatch = monkeyPatch
|
|
4
|
-
|
|
5
|
-
function monkeyPatch () {
|
|
6
|
-
Object.defineProperty(Array.prototype, 'abbrev', {
|
|
7
|
-
value: function () { return abbrev(this) },
|
|
8
|
-
enumerable: false, configurable: true, writable: true
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(Object.prototype, 'abbrev', {
|
|
12
|
-
value: function () { return abbrev(Object.keys(this)) },
|
|
13
|
-
enumerable: false, configurable: true, writable: true
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function abbrev (list) {
|
|
18
|
-
if (arguments.length !== 1 || !Array.isArray(list)) {
|
|
19
|
-
list = Array.prototype.slice.call(arguments, 0)
|
|
20
|
-
}
|
|
21
|
-
for (var i = 0, l = list.length, args = [] ; i < l ; i ++) {
|
|
22
|
-
args[i] = typeof list[i] === "string" ? list[i] : String(list[i])
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// sort them lexicographically, so that they're next to their nearest kin
|
|
26
|
-
args = args.sort(lexSort)
|
|
27
|
-
|
|
28
|
-
// walk through each, seeing how much it has in common with the next and previous
|
|
29
|
-
var abbrevs = {}
|
|
30
|
-
, prev = ""
|
|
31
|
-
for (var i = 0, l = args.length ; i < l ; i ++) {
|
|
32
|
-
var current = args[i]
|
|
33
|
-
, next = args[i + 1] || ""
|
|
34
|
-
, nextMatches = true
|
|
35
|
-
, prevMatches = true
|
|
36
|
-
if (current === next) continue
|
|
37
|
-
for (var j = 0, cl = current.length ; j < cl ; j ++) {
|
|
38
|
-
var curChar = current.charAt(j)
|
|
39
|
-
nextMatches = nextMatches && curChar === next.charAt(j)
|
|
40
|
-
prevMatches = prevMatches && curChar === prev.charAt(j)
|
|
41
|
-
if (!nextMatches && !prevMatches) {
|
|
42
|
-
j ++
|
|
43
|
-
break
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
prev = current
|
|
47
|
-
if (j === cl) {
|
|
48
|
-
abbrevs[current] = current
|
|
49
|
-
continue
|
|
50
|
-
}
|
|
51
|
-
for (var a = current.substr(0, j) ; j <= cl ; j ++) {
|
|
52
|
-
abbrevs[a] = current
|
|
53
|
-
a += current.charAt(j)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return abbrevs
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function lexSort (a, b) {
|
|
60
|
-
return a === b ? 0 : a > b ? 1 : -1
|
|
61
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "abbrev",
|
|
3
|
-
"version": "1.1.1",
|
|
4
|
-
"description": "Like ruby's abbrev module, but in js",
|
|
5
|
-
"author": "Isaac Z. Schlueter <i@izs.me>",
|
|
6
|
-
"main": "abbrev.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "tap test.js --100",
|
|
9
|
-
"preversion": "npm test",
|
|
10
|
-
"postversion": "npm publish",
|
|
11
|
-
"postpublish": "git push origin --all; git push origin --tags"
|
|
12
|
-
},
|
|
13
|
-
"repository": "http://github.com/isaacs/abbrev-js",
|
|
14
|
-
"license": "ISC",
|
|
15
|
-
"devDependencies": {
|
|
16
|
-
"tap": "^10.1"
|
|
17
|
-
},
|
|
18
|
-
"files": [
|
|
19
|
-
"abbrev.js"
|
|
20
|
-
]
|
|
21
|
-
}
|
|
File without changes
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
|
|
2
|
-
All rights reserved.
|
|
3
|
-
|
|
4
|
-
Permission is hereby granted, free of charge, to any person
|
|
5
|
-
obtaining a copy of this software and associated documentation
|
|
6
|
-
files (the "Software"), to deal in the Software without
|
|
7
|
-
restriction, including without limitation the rights to use,
|
|
8
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the
|
|
10
|
-
Software is furnished to do so, subject to the following
|
|
11
|
-
conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
included in all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
18
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
20
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
21
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
22
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
23
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
If you want to write an option parser, and have it be good, there are
|
|
2
|
-
two ways to do it. The Right Way, and the Wrong Way.
|
|
3
|
-
|
|
4
|
-
The Wrong Way is to sit down and write an option parser. We've all done
|
|
5
|
-
that.
|
|
6
|
-
|
|
7
|
-
The Right Way is to write some complex configurable program with so many
|
|
8
|
-
options that you go half-insane just trying to manage them all, and put
|
|
9
|
-
it off with duct-tape solutions until you see exactly to the core of the
|
|
10
|
-
problem, and finally snap and write an awesome option parser.
|
|
11
|
-
|
|
12
|
-
If you want to write an option parser, don't write an option parser.
|
|
13
|
-
Write a package manager, or a source control system, or a service
|
|
14
|
-
restarter, or an operating system. You probably won't end up with a
|
|
15
|
-
good one of those, but if you don't give up, and you are relentless and
|
|
16
|
-
diligent enough in your procrastination, you may just end up with a very
|
|
17
|
-
nice option parser.
|
|
18
|
-
|
|
19
|
-
## USAGE
|
|
20
|
-
|
|
21
|
-
// my-program.js
|
|
22
|
-
var nopt = require("nopt")
|
|
23
|
-
, Stream = require("stream").Stream
|
|
24
|
-
, path = require("path")
|
|
25
|
-
, knownOpts = { "foo" : [String, null]
|
|
26
|
-
, "bar" : [Stream, Number]
|
|
27
|
-
, "baz" : path
|
|
28
|
-
, "bloo" : [ "big", "medium", "small" ]
|
|
29
|
-
, "flag" : Boolean
|
|
30
|
-
, "pick" : Boolean
|
|
31
|
-
, "many" : [String, Array]
|
|
32
|
-
}
|
|
33
|
-
, shortHands = { "foofoo" : ["--foo", "Mr. Foo"]
|
|
34
|
-
, "b7" : ["--bar", "7"]
|
|
35
|
-
, "m" : ["--bloo", "medium"]
|
|
36
|
-
, "p" : ["--pick"]
|
|
37
|
-
, "f" : ["--flag"]
|
|
38
|
-
}
|
|
39
|
-
// everything is optional.
|
|
40
|
-
// knownOpts and shorthands default to {}
|
|
41
|
-
// arg list defaults to process.argv
|
|
42
|
-
// slice defaults to 2
|
|
43
|
-
, parsed = nopt(knownOpts, shortHands, process.argv, 2)
|
|
44
|
-
console.log(parsed)
|
|
45
|
-
|
|
46
|
-
This would give you support for any of the following:
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
$ node my-program.js --foo "blerp" --no-flag
|
|
50
|
-
{ "foo" : "blerp", "flag" : false }
|
|
51
|
-
|
|
52
|
-
$ node my-program.js ---bar 7 --foo "Mr. Hand" --flag
|
|
53
|
-
{ bar: 7, foo: "Mr. Hand", flag: true }
|
|
54
|
-
|
|
55
|
-
$ node my-program.js --foo "blerp" -f -----p
|
|
56
|
-
{ foo: "blerp", flag: true, pick: true }
|
|
57
|
-
|
|
58
|
-
$ node my-program.js -fp --foofoo
|
|
59
|
-
{ foo: "Mr. Foo", flag: true, pick: true }
|
|
60
|
-
|
|
61
|
-
$ node my-program.js --foofoo -- -fp # -- stops the flag parsing.
|
|
62
|
-
{ foo: "Mr. Foo", argv: { remain: ["-fp"] } }
|
|
63
|
-
|
|
64
|
-
$ node my-program.js --blatzk 1000 -fp # unknown opts are ok.
|
|
65
|
-
{ blatzk: 1000, flag: true, pick: true }
|
|
66
|
-
|
|
67
|
-
$ node my-program.js --blatzk true -fp # but they need a value
|
|
68
|
-
{ blatzk: true, flag: true, pick: true }
|
|
69
|
-
|
|
70
|
-
$ node my-program.js --no-blatzk -fp # unless they start with "no-"
|
|
71
|
-
{ blatzk: false, flag: true, pick: true }
|
|
72
|
-
|
|
73
|
-
$ node my-program.js --baz b/a/z # known paths are resolved.
|
|
74
|
-
{ baz: "/Users/isaacs/b/a/z" }
|
|
75
|
-
|
|
76
|
-
# if Array is one of the types, then it can take many
|
|
77
|
-
# values, and will always be an array. The other types provided
|
|
78
|
-
# specify what types are allowed in the list.
|
|
79
|
-
|
|
80
|
-
$ node my-program.js --many 1 --many null --many foo
|
|
81
|
-
{ many: ["1", "null", "foo"] }
|
|
82
|
-
|
|
83
|
-
$ node my-program.js --many foo
|
|
84
|
-
{ many: ["foo"] }
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Read the tests at the bottom of `lib/nopt.js` for more examples of
|
|
88
|
-
what this puppy can do.
|
|
89
|
-
|
|
90
|
-
## Types
|
|
91
|
-
|
|
92
|
-
The following types are supported, and defined on `nopt.typeDefs`
|
|
93
|
-
|
|
94
|
-
* String: A normal string. No parsing is done.
|
|
95
|
-
* path: A file system path. Gets resolved against cwd if not absolute.
|
|
96
|
-
* url: A url. If it doesn't parse, it isn't accepted.
|
|
97
|
-
* Number: Must be numeric.
|
|
98
|
-
* Date: Must parse as a date. If it does, and `Date` is one of the options,
|
|
99
|
-
then it will return a Date object, not a string.
|
|
100
|
-
* Boolean: Must be either `true` or `false`. If an option is a boolean,
|
|
101
|
-
then it does not need a value, and its presence will imply `true` as
|
|
102
|
-
the value. To negate boolean flags, do `--no-whatever` or `--whatever
|
|
103
|
-
false`
|
|
104
|
-
* NaN: Means that the option is strictly not allowed. Any value will
|
|
105
|
-
fail.
|
|
106
|
-
* Stream: An object matching the "Stream" class in node. Valuable
|
|
107
|
-
for use when validating programmatically. (npm uses this to let you
|
|
108
|
-
supply any WriteStream on the `outfd` and `logfd` config options.)
|
|
109
|
-
* Array: If `Array` is specified as one of the types, then the value
|
|
110
|
-
will be parsed as a list of options. This means that multiple values
|
|
111
|
-
can be specified, and that the value will always be an array.
|
|
112
|
-
|
|
113
|
-
If a type is an array of values not on this list, then those are
|
|
114
|
-
considered valid values. For instance, in the example above, the
|
|
115
|
-
`--bloo` option can only be one of `"big"`, `"medium"`, or `"small"`,
|
|
116
|
-
and any other value will be rejected.
|
|
117
|
-
|
|
118
|
-
When parsing unknown fields, `"true"`, `"false"`, and `"null"` will be
|
|
119
|
-
interpreted as their JavaScript equivalents, and numeric values will be
|
|
120
|
-
interpreted as a number.
|
|
121
|
-
|
|
122
|
-
You can also mix types and values, or multiple types, in a list. For
|
|
123
|
-
instance `{ blah: [Number, null] }` would allow a value to be set to
|
|
124
|
-
either a Number or null.
|
|
125
|
-
|
|
126
|
-
To define a new type, add it to `nopt.typeDefs`. Each item in that
|
|
127
|
-
hash is an object with a `type` member and a `validate` method. The
|
|
128
|
-
`type` member is an object that matches what goes in the type list. The
|
|
129
|
-
`validate` method is a function that gets called with `validate(data,
|
|
130
|
-
key, val)`. Validate methods should assign `data[key]` to the valid
|
|
131
|
-
value of `val` if it can be handled properly, or return boolean
|
|
132
|
-
`false` if it cannot.
|
|
133
|
-
|
|
134
|
-
You can also call `nopt.clean(data, types, typeDefs)` to clean up a
|
|
135
|
-
config object and remove its invalid properties.
|
|
136
|
-
|
|
137
|
-
## Error Handling
|
|
138
|
-
|
|
139
|
-
By default, nopt outputs a warning to standard error when invalid
|
|
140
|
-
options are found. You can change this behavior by assigning a method
|
|
141
|
-
to `nopt.invalidHandler`. This method will be called with
|
|
142
|
-
the offending `nopt.invalidHandler(key, val, types)`.
|
|
143
|
-
|
|
144
|
-
If no `nopt.invalidHandler` is assigned, then it will console.error
|
|
145
|
-
its whining. If it is assigned to boolean `false` then the warning is
|
|
146
|
-
suppressed.
|
|
147
|
-
|
|
148
|
-
## Abbreviations
|
|
149
|
-
|
|
150
|
-
Yes, they are supported. If you define options like this:
|
|
151
|
-
|
|
152
|
-
```javascript
|
|
153
|
-
{ "foolhardyelephants" : Boolean
|
|
154
|
-
, "pileofmonkeys" : Boolean }
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
Then this will work:
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
node program.js --foolhar --pil
|
|
161
|
-
node program.js --no-f --pileofmon
|
|
162
|
-
# etc.
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
## Shorthands
|
|
166
|
-
|
|
167
|
-
Shorthands are a hash of shorter option names to a snippet of args that
|
|
168
|
-
they expand to.
|
|
169
|
-
|
|
170
|
-
If multiple one-character shorthands are all combined, and the
|
|
171
|
-
combination does not unambiguously match any other option or shorthand,
|
|
172
|
-
then they will be broken up into their constituent parts. For example:
|
|
173
|
-
|
|
174
|
-
```json
|
|
175
|
-
{ "s" : ["--loglevel", "silent"]
|
|
176
|
-
, "g" : "--global"
|
|
177
|
-
, "f" : "--force"
|
|
178
|
-
, "p" : "--parseable"
|
|
179
|
-
, "l" : "--long"
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
```bash
|
|
184
|
-
npm ls -sgflp
|
|
185
|
-
# just like doing this:
|
|
186
|
-
npm ls --loglevel silent --global --force --long --parseable
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## The Rest of the args
|
|
190
|
-
|
|
191
|
-
The config object returned by nopt is given a special member called
|
|
192
|
-
`argv`, which is an object with the following fields:
|
|
193
|
-
|
|
194
|
-
* `remain`: The remaining args after all the parsing has occurred.
|
|
195
|
-
* `original`: The args as they originally appeared.
|
|
196
|
-
* `cooked`: The args after flags and shorthands are expanded.
|
|
197
|
-
|
|
198
|
-
## Slicing
|
|
199
|
-
|
|
200
|
-
Node programs are called with more or less the exact argv as it appears
|
|
201
|
-
in C land, after the v8 and node-specific options have been plucked off.
|
|
202
|
-
As such, `argv[0]` is always `node` and `argv[1]` is always the
|
|
203
|
-
JavaScript program being run.
|
|
204
|
-
|
|
205
|
-
That's usually not very useful to you. So they're sliced off by
|
|
206
|
-
default. If you want them, then you can pass in `0` as the last
|
|
207
|
-
argument, or any other number that you'd like to slice off the start of
|
|
208
|
-
the list.
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
var nopt = require("../lib/nopt")
|
|
3
|
-
, types = { num: Number
|
|
4
|
-
, bool: Boolean
|
|
5
|
-
, help: Boolean
|
|
6
|
-
, list: Array
|
|
7
|
-
, "num-list": [Number, Array]
|
|
8
|
-
, "str-list": [String, Array]
|
|
9
|
-
, "bool-list": [Boolean, Array]
|
|
10
|
-
, str: String }
|
|
11
|
-
, shorthands = { s: [ "--str", "astring" ]
|
|
12
|
-
, b: [ "--bool" ]
|
|
13
|
-
, nb: [ "--no-bool" ]
|
|
14
|
-
, tft: [ "--bool-list", "--no-bool-list", "--bool-list", "true" ]
|
|
15
|
-
, "?": ["--help"]
|
|
16
|
-
, h: ["--help"]
|
|
17
|
-
, H: ["--help"]
|
|
18
|
-
, n: [ "--num", "125" ] }
|
|
19
|
-
, parsed = nopt( types
|
|
20
|
-
, shorthands
|
|
21
|
-
, process.argv
|
|
22
|
-
, 2 )
|
|
23
|
-
|
|
24
|
-
console.log("parsed", parsed)
|
|
25
|
-
|
|
26
|
-
if (parsed.help) {
|
|
27
|
-
console.log("")
|
|
28
|
-
console.log("nopt cli tester")
|
|
29
|
-
console.log("")
|
|
30
|
-
console.log("types")
|
|
31
|
-
console.log(Object.keys(types).map(function M (t) {
|
|
32
|
-
var type = types[t]
|
|
33
|
-
if (Array.isArray(type)) {
|
|
34
|
-
return [t, type.map(function (type) { return type.name })]
|
|
35
|
-
}
|
|
36
|
-
return [t, type && type.name]
|
|
37
|
-
}).reduce(function (s, i) {
|
|
38
|
-
s[i[0]] = i[1]
|
|
39
|
-
return s
|
|
40
|
-
}, {}))
|
|
41
|
-
console.log("")
|
|
42
|
-
console.log("shorthands")
|
|
43
|
-
console.log(shorthands)
|
|
44
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
//process.env.DEBUG_NOPT = 1
|
|
4
|
-
|
|
5
|
-
// my-program.js
|
|
6
|
-
var nopt = require("../lib/nopt")
|
|
7
|
-
, Stream = require("stream").Stream
|
|
8
|
-
, path = require("path")
|
|
9
|
-
, knownOpts = { "foo" : [String, null]
|
|
10
|
-
, "bar" : [Stream, Number]
|
|
11
|
-
, "baz" : path
|
|
12
|
-
, "bloo" : [ "big", "medium", "small" ]
|
|
13
|
-
, "flag" : Boolean
|
|
14
|
-
, "pick" : Boolean
|
|
15
|
-
}
|
|
16
|
-
, shortHands = { "foofoo" : ["--foo", "Mr. Foo"]
|
|
17
|
-
, "b7" : ["--bar", "7"]
|
|
18
|
-
, "m" : ["--bloo", "medium"]
|
|
19
|
-
, "p" : ["--pick"]
|
|
20
|
-
, "f" : ["--flag", "true"]
|
|
21
|
-
, "g" : ["--flag"]
|
|
22
|
-
, "s" : "--flag"
|
|
23
|
-
}
|
|
24
|
-
// everything is optional.
|
|
25
|
-
// knownOpts and shorthands default to {}
|
|
26
|
-
// arg list defaults to process.argv
|
|
27
|
-
// slice defaults to 2
|
|
28
|
-
, parsed = nopt(knownOpts, shortHands, process.argv, 2)
|
|
29
|
-
|
|
30
|
-
console.log("parsed =\n"+ require("util").inspect(parsed))
|
|
@@ -1,552 +0,0 @@
|
|
|
1
|
-
// info about each config option.
|
|
2
|
-
|
|
3
|
-
var debug = process.env.DEBUG_NOPT || process.env.NOPT_DEBUG
|
|
4
|
-
? function () { console.error.apply(console, arguments) }
|
|
5
|
-
: function () {}
|
|
6
|
-
|
|
7
|
-
var url = require("url")
|
|
8
|
-
, path = require("path")
|
|
9
|
-
, Stream = require("stream").Stream
|
|
10
|
-
, abbrev = require("abbrev")
|
|
11
|
-
|
|
12
|
-
module.exports = exports = nopt
|
|
13
|
-
exports.clean = clean
|
|
14
|
-
|
|
15
|
-
exports.typeDefs =
|
|
16
|
-
{ String : { type: String, validate: validateString }
|
|
17
|
-
, Boolean : { type: Boolean, validate: validateBoolean }
|
|
18
|
-
, url : { type: url, validate: validateUrl }
|
|
19
|
-
, Number : { type: Number, validate: validateNumber }
|
|
20
|
-
, path : { type: path, validate: validatePath }
|
|
21
|
-
, Stream : { type: Stream, validate: validateStream }
|
|
22
|
-
, Date : { type: Date, validate: validateDate }
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function nopt (types, shorthands, args, slice) {
|
|
26
|
-
args = args || process.argv
|
|
27
|
-
types = types || {}
|
|
28
|
-
shorthands = shorthands || {}
|
|
29
|
-
if (typeof slice !== "number") slice = 2
|
|
30
|
-
|
|
31
|
-
debug(types, shorthands, args, slice)
|
|
32
|
-
|
|
33
|
-
args = args.slice(slice)
|
|
34
|
-
var data = {}
|
|
35
|
-
, key
|
|
36
|
-
, remain = []
|
|
37
|
-
, cooked = args
|
|
38
|
-
, original = args.slice(0)
|
|
39
|
-
|
|
40
|
-
parse(args, data, remain, types, shorthands)
|
|
41
|
-
// now data is full
|
|
42
|
-
clean(data, types, exports.typeDefs)
|
|
43
|
-
data.argv = {remain:remain,cooked:cooked,original:original}
|
|
44
|
-
data.argv.toString = function () {
|
|
45
|
-
return this.original.map(JSON.stringify).join(" ")
|
|
46
|
-
}
|
|
47
|
-
return data
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function clean (data, types, typeDefs) {
|
|
51
|
-
typeDefs = typeDefs || exports.typeDefs
|
|
52
|
-
var remove = {}
|
|
53
|
-
, typeDefault = [false, true, null, String, Number]
|
|
54
|
-
|
|
55
|
-
Object.keys(data).forEach(function (k) {
|
|
56
|
-
if (k === "argv") return
|
|
57
|
-
var val = data[k]
|
|
58
|
-
, isArray = Array.isArray(val)
|
|
59
|
-
, type = types[k]
|
|
60
|
-
if (!isArray) val = [val]
|
|
61
|
-
if (!type) type = typeDefault
|
|
62
|
-
if (type === Array) type = typeDefault.concat(Array)
|
|
63
|
-
if (!Array.isArray(type)) type = [type]
|
|
64
|
-
|
|
65
|
-
debug("val=%j", val)
|
|
66
|
-
debug("types=", type)
|
|
67
|
-
val = val.map(function (val) {
|
|
68
|
-
// if it's an unknown value, then parse false/true/null/numbers/dates
|
|
69
|
-
if (typeof val === "string") {
|
|
70
|
-
debug("string %j", val)
|
|
71
|
-
val = val.trim()
|
|
72
|
-
if ((val === "null" && ~type.indexOf(null))
|
|
73
|
-
|| (val === "true" &&
|
|
74
|
-
(~type.indexOf(true) || ~type.indexOf(Boolean)))
|
|
75
|
-
|| (val === "false" &&
|
|
76
|
-
(~type.indexOf(false) || ~type.indexOf(Boolean)))) {
|
|
77
|
-
val = JSON.parse(val)
|
|
78
|
-
debug("jsonable %j", val)
|
|
79
|
-
} else if (~type.indexOf(Number) && !isNaN(val)) {
|
|
80
|
-
debug("convert to number", val)
|
|
81
|
-
val = +val
|
|
82
|
-
} else if (~type.indexOf(Date) && !isNaN(Date.parse(val))) {
|
|
83
|
-
debug("convert to date", val)
|
|
84
|
-
val = new Date(val)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!types.hasOwnProperty(k)) {
|
|
89
|
-
return val
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// allow `--no-blah` to set 'blah' to null if null is allowed
|
|
93
|
-
if (val === false && ~type.indexOf(null) &&
|
|
94
|
-
!(~type.indexOf(false) || ~type.indexOf(Boolean))) {
|
|
95
|
-
val = null
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
var d = {}
|
|
99
|
-
d[k] = val
|
|
100
|
-
debug("prevalidated val", d, val, types[k])
|
|
101
|
-
if (!validate(d, k, val, types[k], typeDefs)) {
|
|
102
|
-
if (exports.invalidHandler) {
|
|
103
|
-
exports.invalidHandler(k, val, types[k], data)
|
|
104
|
-
} else if (exports.invalidHandler !== false) {
|
|
105
|
-
debug("invalid: "+k+"="+val, types[k])
|
|
106
|
-
}
|
|
107
|
-
return remove
|
|
108
|
-
}
|
|
109
|
-
debug("validated val", d, val, types[k])
|
|
110
|
-
return d[k]
|
|
111
|
-
}).filter(function (val) { return val !== remove })
|
|
112
|
-
|
|
113
|
-
if (!val.length) delete data[k]
|
|
114
|
-
else if (isArray) {
|
|
115
|
-
debug(isArray, data[k], val)
|
|
116
|
-
data[k] = val
|
|
117
|
-
} else data[k] = val[0]
|
|
118
|
-
|
|
119
|
-
debug("k=%s val=%j", k, val, data[k])
|
|
120
|
-
})
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function validateString (data, k, val) {
|
|
124
|
-
data[k] = String(val)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function validatePath (data, k, val) {
|
|
128
|
-
data[k] = path.resolve(String(val))
|
|
129
|
-
return true
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function validateNumber (data, k, val) {
|
|
133
|
-
debug("validate Number %j %j %j", k, val, isNaN(val))
|
|
134
|
-
if (isNaN(val)) return false
|
|
135
|
-
data[k] = +val
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function validateDate (data, k, val) {
|
|
139
|
-
debug("validate Date %j %j %j", k, val, Date.parse(val))
|
|
140
|
-
var s = Date.parse(val)
|
|
141
|
-
if (isNaN(s)) return false
|
|
142
|
-
data[k] = new Date(val)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function validateBoolean (data, k, val) {
|
|
146
|
-
if (val instanceof Boolean) val = val.valueOf()
|
|
147
|
-
else if (typeof val === "string") {
|
|
148
|
-
if (!isNaN(val)) val = !!(+val)
|
|
149
|
-
else if (val === "null" || val === "false") val = false
|
|
150
|
-
else val = true
|
|
151
|
-
} else val = !!val
|
|
152
|
-
data[k] = val
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function validateUrl (data, k, val) {
|
|
156
|
-
val = url.parse(String(val))
|
|
157
|
-
if (!val.host) return false
|
|
158
|
-
data[k] = val.href
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function validateStream (data, k, val) {
|
|
162
|
-
if (!(val instanceof Stream)) return false
|
|
163
|
-
data[k] = val
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function validate (data, k, val, type, typeDefs) {
|
|
167
|
-
// arrays are lists of types.
|
|
168
|
-
if (Array.isArray(type)) {
|
|
169
|
-
for (var i = 0, l = type.length; i < l; i ++) {
|
|
170
|
-
if (type[i] === Array) continue
|
|
171
|
-
if (validate(data, k, val, type[i], typeDefs)) return true
|
|
172
|
-
}
|
|
173
|
-
delete data[k]
|
|
174
|
-
return false
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// an array of anything?
|
|
178
|
-
if (type === Array) return true
|
|
179
|
-
|
|
180
|
-
// NaN is poisonous. Means that something is not allowed.
|
|
181
|
-
if (type !== type) {
|
|
182
|
-
debug("Poison NaN", k, val, type)
|
|
183
|
-
delete data[k]
|
|
184
|
-
return false
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// explicit list of values
|
|
188
|
-
if (val === type) {
|
|
189
|
-
debug("Explicitly allowed %j", val)
|
|
190
|
-
// if (isArray) (data[k] = data[k] || []).push(val)
|
|
191
|
-
// else data[k] = val
|
|
192
|
-
data[k] = val
|
|
193
|
-
return true
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// now go through the list of typeDefs, validate against each one.
|
|
197
|
-
var ok = false
|
|
198
|
-
, types = Object.keys(typeDefs)
|
|
199
|
-
for (var i = 0, l = types.length; i < l; i ++) {
|
|
200
|
-
debug("test type %j %j %j", k, val, types[i])
|
|
201
|
-
var t = typeDefs[types[i]]
|
|
202
|
-
if (t && type === t.type) {
|
|
203
|
-
var d = {}
|
|
204
|
-
ok = false !== t.validate(d, k, val)
|
|
205
|
-
val = d[k]
|
|
206
|
-
if (ok) {
|
|
207
|
-
// if (isArray) (data[k] = data[k] || []).push(val)
|
|
208
|
-
// else data[k] = val
|
|
209
|
-
data[k] = val
|
|
210
|
-
break
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
debug("OK? %j (%j %j %j)", ok, k, val, types[i])
|
|
215
|
-
|
|
216
|
-
if (!ok) delete data[k]
|
|
217
|
-
return ok
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function parse (args, data, remain, types, shorthands) {
|
|
221
|
-
debug("parse", args, data, remain)
|
|
222
|
-
|
|
223
|
-
var key = null
|
|
224
|
-
, abbrevs = abbrev(Object.keys(types))
|
|
225
|
-
, shortAbbr = abbrev(Object.keys(shorthands))
|
|
226
|
-
|
|
227
|
-
for (var i = 0; i < args.length; i ++) {
|
|
228
|
-
var arg = args[i]
|
|
229
|
-
debug("arg", arg)
|
|
230
|
-
|
|
231
|
-
if (arg.match(/^-{2,}$/)) {
|
|
232
|
-
// done with keys.
|
|
233
|
-
// the rest are args.
|
|
234
|
-
remain.push.apply(remain, args.slice(i + 1))
|
|
235
|
-
args[i] = "--"
|
|
236
|
-
break
|
|
237
|
-
}
|
|
238
|
-
if (arg.charAt(0) === "-") {
|
|
239
|
-
if (arg.indexOf("=") !== -1) {
|
|
240
|
-
var v = arg.split("=")
|
|
241
|
-
arg = v.shift()
|
|
242
|
-
v = v.join("=")
|
|
243
|
-
args.splice.apply(args, [i, 1].concat([arg, v]))
|
|
244
|
-
}
|
|
245
|
-
// see if it's a shorthand
|
|
246
|
-
// if so, splice and back up to re-parse it.
|
|
247
|
-
var shRes = resolveShort(arg, shorthands, shortAbbr, abbrevs)
|
|
248
|
-
debug("arg=%j shRes=%j", arg, shRes)
|
|
249
|
-
if (shRes) {
|
|
250
|
-
debug(arg, shRes)
|
|
251
|
-
args.splice.apply(args, [i, 1].concat(shRes))
|
|
252
|
-
if (arg !== shRes[0]) {
|
|
253
|
-
i --
|
|
254
|
-
continue
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
arg = arg.replace(/^-+/, "")
|
|
258
|
-
var no = false
|
|
259
|
-
while (arg.toLowerCase().indexOf("no-") === 0) {
|
|
260
|
-
no = !no
|
|
261
|
-
arg = arg.substr(3)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (abbrevs[arg]) arg = abbrevs[arg]
|
|
265
|
-
|
|
266
|
-
var isArray = types[arg] === Array ||
|
|
267
|
-
Array.isArray(types[arg]) && types[arg].indexOf(Array) !== -1
|
|
268
|
-
|
|
269
|
-
var val
|
|
270
|
-
, la = args[i + 1]
|
|
271
|
-
|
|
272
|
-
var isBool = no ||
|
|
273
|
-
types[arg] === Boolean ||
|
|
274
|
-
Array.isArray(types[arg]) && types[arg].indexOf(Boolean) !== -1 ||
|
|
275
|
-
(la === "false" &&
|
|
276
|
-
(types[arg] === null ||
|
|
277
|
-
Array.isArray(types[arg]) && ~types[arg].indexOf(null)))
|
|
278
|
-
|
|
279
|
-
if (isBool) {
|
|
280
|
-
// just set and move along
|
|
281
|
-
val = !no
|
|
282
|
-
// however, also support --bool true or --bool false
|
|
283
|
-
if (la === "true" || la === "false") {
|
|
284
|
-
val = JSON.parse(la)
|
|
285
|
-
la = null
|
|
286
|
-
if (no) val = !val
|
|
287
|
-
i ++
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// also support "foo":[Boolean, "bar"] and "--foo bar"
|
|
291
|
-
if (Array.isArray(types[arg]) && la) {
|
|
292
|
-
if (~types[arg].indexOf(la)) {
|
|
293
|
-
// an explicit type
|
|
294
|
-
val = la
|
|
295
|
-
i ++
|
|
296
|
-
} else if ( la === "null" && ~types[arg].indexOf(null) ) {
|
|
297
|
-
// null allowed
|
|
298
|
-
val = null
|
|
299
|
-
i ++
|
|
300
|
-
} else if ( !la.match(/^-{2,}[^-]/) &&
|
|
301
|
-
!isNaN(la) &&
|
|
302
|
-
~types[arg].indexOf(Number) ) {
|
|
303
|
-
// number
|
|
304
|
-
val = +la
|
|
305
|
-
i ++
|
|
306
|
-
} else if ( !la.match(/^-[^-]/) && ~types[arg].indexOf(String) ) {
|
|
307
|
-
// string
|
|
308
|
-
val = la
|
|
309
|
-
i ++
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (isArray) (data[arg] = data[arg] || []).push(val)
|
|
314
|
-
else data[arg] = val
|
|
315
|
-
|
|
316
|
-
continue
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (la && la.match(/^-{2,}$/)) {
|
|
320
|
-
la = undefined
|
|
321
|
-
i --
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
val = la === undefined ? true : la
|
|
325
|
-
if (isArray) (data[arg] = data[arg] || []).push(val)
|
|
326
|
-
else data[arg] = val
|
|
327
|
-
|
|
328
|
-
i ++
|
|
329
|
-
continue
|
|
330
|
-
}
|
|
331
|
-
remain.push(arg)
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function resolveShort (arg, shorthands, shortAbbr, abbrevs) {
|
|
336
|
-
// handle single-char shorthands glommed together, like
|
|
337
|
-
// npm ls -glp, but only if there is one dash, and only if
|
|
338
|
-
// all of the chars are single-char shorthands, and it's
|
|
339
|
-
// not a match to some other abbrev.
|
|
340
|
-
arg = arg.replace(/^-+/, '')
|
|
341
|
-
if (abbrevs[arg] && !shorthands[arg]) {
|
|
342
|
-
return null
|
|
343
|
-
}
|
|
344
|
-
if (shortAbbr[arg]) {
|
|
345
|
-
arg = shortAbbr[arg]
|
|
346
|
-
} else {
|
|
347
|
-
var singles = shorthands.___singles
|
|
348
|
-
if (!singles) {
|
|
349
|
-
singles = Object.keys(shorthands).filter(function (s) {
|
|
350
|
-
return s.length === 1
|
|
351
|
-
}).reduce(function (l,r) { l[r] = true ; return l }, {})
|
|
352
|
-
shorthands.___singles = singles
|
|
353
|
-
}
|
|
354
|
-
var chrs = arg.split("").filter(function (c) {
|
|
355
|
-
return singles[c]
|
|
356
|
-
})
|
|
357
|
-
if (chrs.join("") === arg) return chrs.map(function (c) {
|
|
358
|
-
return shorthands[c]
|
|
359
|
-
}).reduce(function (l, r) {
|
|
360
|
-
return l.concat(r)
|
|
361
|
-
}, [])
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (shorthands[arg] && !Array.isArray(shorthands[arg])) {
|
|
365
|
-
shorthands[arg] = shorthands[arg].split(/\s+/)
|
|
366
|
-
}
|
|
367
|
-
return shorthands[arg]
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
if (module === require.main) {
|
|
371
|
-
var assert = require("assert")
|
|
372
|
-
, util = require("util")
|
|
373
|
-
|
|
374
|
-
, shorthands =
|
|
375
|
-
{ s : ["--loglevel", "silent"]
|
|
376
|
-
, d : ["--loglevel", "info"]
|
|
377
|
-
, dd : ["--loglevel", "verbose"]
|
|
378
|
-
, ddd : ["--loglevel", "silly"]
|
|
379
|
-
, noreg : ["--no-registry"]
|
|
380
|
-
, reg : ["--registry"]
|
|
381
|
-
, "no-reg" : ["--no-registry"]
|
|
382
|
-
, silent : ["--loglevel", "silent"]
|
|
383
|
-
, verbose : ["--loglevel", "verbose"]
|
|
384
|
-
, h : ["--usage"]
|
|
385
|
-
, H : ["--usage"]
|
|
386
|
-
, "?" : ["--usage"]
|
|
387
|
-
, help : ["--usage"]
|
|
388
|
-
, v : ["--version"]
|
|
389
|
-
, f : ["--force"]
|
|
390
|
-
, desc : ["--description"]
|
|
391
|
-
, "no-desc" : ["--no-description"]
|
|
392
|
-
, "local" : ["--no-global"]
|
|
393
|
-
, l : ["--long"]
|
|
394
|
-
, p : ["--parseable"]
|
|
395
|
-
, porcelain : ["--parseable"]
|
|
396
|
-
, g : ["--global"]
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
, types =
|
|
400
|
-
{ aoa: Array
|
|
401
|
-
, nullstream: [null, Stream]
|
|
402
|
-
, date: Date
|
|
403
|
-
, str: String
|
|
404
|
-
, browser : String
|
|
405
|
-
, cache : path
|
|
406
|
-
, color : ["always", Boolean]
|
|
407
|
-
, depth : Number
|
|
408
|
-
, description : Boolean
|
|
409
|
-
, dev : Boolean
|
|
410
|
-
, editor : path
|
|
411
|
-
, force : Boolean
|
|
412
|
-
, global : Boolean
|
|
413
|
-
, globalconfig : path
|
|
414
|
-
, group : [String, Number]
|
|
415
|
-
, gzipbin : String
|
|
416
|
-
, logfd : [Number, Stream]
|
|
417
|
-
, loglevel : ["silent","win","error","warn","info","verbose","silly"]
|
|
418
|
-
, long : Boolean
|
|
419
|
-
, "node-version" : [false, String]
|
|
420
|
-
, npaturl : url
|
|
421
|
-
, npat : Boolean
|
|
422
|
-
, "onload-script" : [false, String]
|
|
423
|
-
, outfd : [Number, Stream]
|
|
424
|
-
, parseable : Boolean
|
|
425
|
-
, pre: Boolean
|
|
426
|
-
, prefix: path
|
|
427
|
-
, proxy : url
|
|
428
|
-
, "rebuild-bundle" : Boolean
|
|
429
|
-
, registry : url
|
|
430
|
-
, searchopts : String
|
|
431
|
-
, searchexclude: [null, String]
|
|
432
|
-
, shell : path
|
|
433
|
-
, t: [Array, String]
|
|
434
|
-
, tag : String
|
|
435
|
-
, tar : String
|
|
436
|
-
, tmp : path
|
|
437
|
-
, "unsafe-perm" : Boolean
|
|
438
|
-
, usage : Boolean
|
|
439
|
-
, user : String
|
|
440
|
-
, username : String
|
|
441
|
-
, userconfig : path
|
|
442
|
-
, version : Boolean
|
|
443
|
-
, viewer: path
|
|
444
|
-
, _exit : Boolean
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
; [["-v", {version:true}, []]
|
|
448
|
-
,["---v", {version:true}, []]
|
|
449
|
-
,["ls -s --no-reg connect -d",
|
|
450
|
-
{loglevel:"info",registry:null},["ls","connect"]]
|
|
451
|
-
,["ls ---s foo",{loglevel:"silent"},["ls","foo"]]
|
|
452
|
-
,["ls --registry blargle", {}, ["ls"]]
|
|
453
|
-
,["--no-registry", {registry:null}, []]
|
|
454
|
-
,["--no-color true", {color:false}, []]
|
|
455
|
-
,["--no-color false", {color:true}, []]
|
|
456
|
-
,["--no-color", {color:false}, []]
|
|
457
|
-
,["--color false", {color:false}, []]
|
|
458
|
-
,["--color --logfd 7", {logfd:7,color:true}, []]
|
|
459
|
-
,["--color=true", {color:true}, []]
|
|
460
|
-
,["--logfd=10", {logfd:10}, []]
|
|
461
|
-
,["--tmp=/tmp -tar=gtar",{tmp:"/tmp",tar:"gtar"},[]]
|
|
462
|
-
,["--tmp=tmp -tar=gtar",
|
|
463
|
-
{tmp:path.resolve(process.cwd(), "tmp"),tar:"gtar"},[]]
|
|
464
|
-
,["--logfd x", {}, []]
|
|
465
|
-
,["a -true -- -no-false", {true:true},["a","-no-false"]]
|
|
466
|
-
,["a -no-false", {false:false},["a"]]
|
|
467
|
-
,["a -no-no-true", {true:true}, ["a"]]
|
|
468
|
-
,["a -no-no-no-false", {false:false}, ["a"]]
|
|
469
|
-
,["---NO-no-No-no-no-no-nO-no-no"+
|
|
470
|
-
"-No-no-no-no-no-no-no-no-no"+
|
|
471
|
-
"-no-no-no-no-NO-NO-no-no-no-no-no-no"+
|
|
472
|
-
"-no-body-can-do-the-boogaloo-like-I-do"
|
|
473
|
-
,{"body-can-do-the-boogaloo-like-I-do":false}, []]
|
|
474
|
-
,["we are -no-strangers-to-love "+
|
|
475
|
-
"--you-know the-rules --and so-do-i "+
|
|
476
|
-
"---im-thinking-of=a-full-commitment "+
|
|
477
|
-
"--no-you-would-get-this-from-any-other-guy "+
|
|
478
|
-
"--no-gonna-give-you-up "+
|
|
479
|
-
"-no-gonna-let-you-down=true "+
|
|
480
|
-
"--no-no-gonna-run-around false "+
|
|
481
|
-
"--desert-you=false "+
|
|
482
|
-
"--make-you-cry false "+
|
|
483
|
-
"--no-tell-a-lie "+
|
|
484
|
-
"--no-no-and-hurt-you false"
|
|
485
|
-
,{"strangers-to-love":false
|
|
486
|
-
,"you-know":"the-rules"
|
|
487
|
-
,"and":"so-do-i"
|
|
488
|
-
,"you-would-get-this-from-any-other-guy":false
|
|
489
|
-
,"gonna-give-you-up":false
|
|
490
|
-
,"gonna-let-you-down":false
|
|
491
|
-
,"gonna-run-around":false
|
|
492
|
-
,"desert-you":false
|
|
493
|
-
,"make-you-cry":false
|
|
494
|
-
,"tell-a-lie":false
|
|
495
|
-
,"and-hurt-you":false
|
|
496
|
-
},["we", "are"]]
|
|
497
|
-
,["-t one -t two -t three"
|
|
498
|
-
,{t: ["one", "two", "three"]}
|
|
499
|
-
,[]]
|
|
500
|
-
,["-t one -t null -t three four five null"
|
|
501
|
-
,{t: ["one", "null", "three"]}
|
|
502
|
-
,["four", "five", "null"]]
|
|
503
|
-
,["-t foo"
|
|
504
|
-
,{t:["foo"]}
|
|
505
|
-
,[]]
|
|
506
|
-
,["--no-t"
|
|
507
|
-
,{t:["false"]}
|
|
508
|
-
,[]]
|
|
509
|
-
,["-no-no-t"
|
|
510
|
-
,{t:["true"]}
|
|
511
|
-
,[]]
|
|
512
|
-
,["-aoa one -aoa null -aoa 100"
|
|
513
|
-
,{aoa:["one", null, 100]}
|
|
514
|
-
,[]]
|
|
515
|
-
,["-str 100"
|
|
516
|
-
,{str:"100"}
|
|
517
|
-
,[]]
|
|
518
|
-
,["--color always"
|
|
519
|
-
,{color:"always"}
|
|
520
|
-
,[]]
|
|
521
|
-
,["--no-nullstream"
|
|
522
|
-
,{nullstream:null}
|
|
523
|
-
,[]]
|
|
524
|
-
,["--nullstream false"
|
|
525
|
-
,{nullstream:null}
|
|
526
|
-
,[]]
|
|
527
|
-
,["--notadate 2011-01-25"
|
|
528
|
-
,{notadate: "2011-01-25"}
|
|
529
|
-
,[]]
|
|
530
|
-
,["--date 2011-01-25"
|
|
531
|
-
,{date: new Date("2011-01-25")}
|
|
532
|
-
,[]]
|
|
533
|
-
].forEach(function (test) {
|
|
534
|
-
var argv = test[0].split(/\s+/)
|
|
535
|
-
, opts = test[1]
|
|
536
|
-
, rem = test[2]
|
|
537
|
-
, actual = nopt(types, shorthands, argv, 0)
|
|
538
|
-
, parsed = actual.argv
|
|
539
|
-
delete actual.argv
|
|
540
|
-
console.log(util.inspect(actual, false, 2, true), parsed.remain)
|
|
541
|
-
for (var i in opts) {
|
|
542
|
-
var e = JSON.stringify(opts[i])
|
|
543
|
-
, a = JSON.stringify(actual[i] === undefined ? null : actual[i])
|
|
544
|
-
if (e && typeof e === "object") {
|
|
545
|
-
assert.deepEqual(e, a)
|
|
546
|
-
} else {
|
|
547
|
-
assert.equal(e, a)
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
assert.deepEqual(rem, parsed.remain)
|
|
551
|
-
})
|
|
552
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{ "name" : "nopt"
|
|
2
|
-
, "version" : "1.0.10"
|
|
3
|
-
, "description" : "Option parsing for Node, supporting types, shorthands, etc. Used by npm."
|
|
4
|
-
, "author" : "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)"
|
|
5
|
-
, "main" : "lib/nopt.js"
|
|
6
|
-
, "scripts" : { "test" : "node lib/nopt.js" }
|
|
7
|
-
, "repository" : "http://github.com/isaacs/nopt"
|
|
8
|
-
, "bin" : "./bin/nopt.js"
|
|
9
|
-
, "license" :
|
|
10
|
-
{ "type" : "MIT"
|
|
11
|
-
, "url" : "https://github.com/isaacs/nopt/raw/master/LICENSE" }
|
|
12
|
-
, "dependencies" : { "abbrev" : "1" }}
|
|
Binary file
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const unzip = require('./unzip');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const http = require('https');
|
|
4
|
-
const process = require('process');
|
|
5
|
-
|
|
6
|
-
console.log('Trying to open', process.argv[2]);
|
|
7
|
-
|
|
8
|
-
let parser = unzip.Parse({debug: false});
|
|
9
|
-
parser.on('end', () => { console.log('ended'); });
|
|
10
|
-
//parser.drainAll();
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
let req = http.get('https://www.colorado.edu/conflict/peace/download/peace_example.ZIP');
|
|
14
|
-
|
|
15
|
-
req.on('response', (resp) => {
|
|
16
|
-
resp.pipe(parser);
|
|
17
|
-
});
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
fs.createReadStream(process.argv[2]).pipe(parser).on('entry', (e) => {
|
|
21
|
-
console.log("entry", e.path);
|
|
22
|
-
if (!e.isDirectory) {
|
|
23
|
-
//console.log("Data for ", e.path);
|
|
24
|
-
e.on('data', (chunk) => {
|
|
25
|
-
//console.log(e.path, ">>>", chunk.length, "byte chunk > ...");
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|