Deployed the page to Github Pages.
This commit is contained in:
parent
1d79754e93
commit
2c89899458
62797 changed files with 6551425 additions and 15279 deletions
15
node_modules/nopt/LICENSE
generated
vendored
Normal file
15
node_modules/nopt/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
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 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.
|
213
node_modules/nopt/README.md
generated
vendored
Normal file
213
node_modules/nopt/README.md
generated
vendored
Normal file
|
@ -0,0 +1,213 @@
|
|||
If you want to write an option parser, and have it be good, there are
|
||||
two ways to do it. The Right Way, and the Wrong Way.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
restarter, or an operating system. You probably won't end up with a
|
||||
good one of those, but if you don't give up, and you are relentless and
|
||||
diligent enough in your procrastination, you may just end up with a very
|
||||
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)
|
||||
```
|
||||
|
||||
This would give you support for any of the following:
|
||||
|
||||
```console
|
||||
$ node my-program.js --foo "blerp" --no-flag
|
||||
{ "foo" : "blerp", "flag" : false }
|
||||
|
||||
$ node my-program.js ---bar 7 --foo "Mr. Hand" --flag
|
||||
{ bar: 7, foo: "Mr. Hand", flag: true }
|
||||
|
||||
$ node my-program.js --foo "blerp" -f -----p
|
||||
{ foo: "blerp", flag: true, pick: true }
|
||||
|
||||
$ node my-program.js -fp --foofoo
|
||||
{ foo: "Mr. Foo", flag: true, pick: true }
|
||||
|
||||
$ 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
|
||||
{ blatzk: 1000, flag: true, pick: true }
|
||||
|
||||
$ node my-program.js --no-blatzk -fp # unless they start with "no-"
|
||||
{ blatzk: false, flag: true, pick: true }
|
||||
|
||||
$ node my-program.js --baz b/a/z # known paths are resolved.
|
||||
{ baz: "/Users/isaacs/b/a/z" }
|
||||
|
||||
# if Array is one of the types, then it can take many
|
||||
# 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 --many2 foo --many2 bar
|
||||
{ many2: ["/path/to/foo", "path/to/bar"] }
|
||||
```
|
||||
|
||||
Read the tests at the bottom of `lib/nopt.js` for more examples of
|
||||
what this puppy can do.
|
||||
|
||||
## Types
|
||||
|
||||
The following types are supported, and defined on `nopt.typeDefs`
|
||||
|
||||
* String: A normal string. No parsing is done.
|
||||
* path: A file system path. Gets resolved against cwd if not absolute.
|
||||
* url: A url. If it doesn't parse, it isn't accepted.
|
||||
* Number: Must be numeric.
|
||||
* Date: Must parse as a date. If it does, and `Date` is one of the options,
|
||||
then it will return a Date object, not a string.
|
||||
* Boolean: Must be either `true` or `false`. If an option is a boolean,
|
||||
then it does not need a value, and its presence will imply `true` as
|
||||
the value. To negate boolean flags, do `--no-whatever` or `--whatever
|
||||
false`
|
||||
* NaN: Means that the option is strictly not allowed. Any value will
|
||||
fail.
|
||||
* Stream: An object matching the "Stream" class in node. Valuable
|
||||
for use when validating programmatically. (npm uses this to let you
|
||||
supply any WriteStream on the `outfd` and `logfd` config options.)
|
||||
* Array: If `Array` is specified as one of the types, then the value
|
||||
will be parsed as a list of options. This means that multiple values
|
||||
can be specified, and that the value will always be an array.
|
||||
|
||||
If a type is an array of values not on this list, then those are
|
||||
considered valid values. For instance, in the example above, the
|
||||
`--bloo` option can only be one of `"big"`, `"medium"`, or `"small"`,
|
||||
and any other value will be rejected.
|
||||
|
||||
When parsing unknown fields, `"true"`, `"false"`, and `"null"` will be
|
||||
interpreted as their JavaScript equivalents.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
`type` member is an object that matches what goes in the type list. The
|
||||
`validate` method is a function that gets called with `validate(data,
|
||||
key, val)`. Validate methods should assign `data[key]` to the valid
|
||||
value of `val` if it can be handled properly, or return boolean
|
||||
`false` if it cannot.
|
||||
|
||||
You can also call `nopt.clean(data, types, typeDefs)` to clean up a
|
||||
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
|
||||
to `nopt.invalidHandler`. This method will be called with
|
||||
the offending `nopt.invalidHandler(key, val, types)`.
|
||||
|
||||
If no `nopt.invalidHandler` is assigned, then it will console.error
|
||||
its whining. If it is assigned to boolean `false` then the warning is
|
||||
suppressed.
|
||||
|
||||
## Abbreviations
|
||||
|
||||
Yes, they are supported. If you define options like this:
|
||||
|
||||
```javascript
|
||||
{ "foolhardyelephants" : Boolean
|
||||
, "pileofmonkeys" : Boolean }
|
||||
```
|
||||
|
||||
Then this will work:
|
||||
|
||||
```bash
|
||||
node program.js --foolhar --pil
|
||||
node program.js --no-f --pileofmon
|
||||
# etc.
|
||||
```
|
||||
|
||||
## Shorthands
|
||||
|
||||
Shorthands are a hash of shorter option names to a snippet of args that
|
||||
they expand to.
|
||||
|
||||
If multiple one-character shorthands are all combined, and the
|
||||
combination does not unambiguously match any other option or shorthand,
|
||||
then they will be broken up into their constituent parts. For example:
|
||||
|
||||
```json
|
||||
{ "s" : ["--loglevel", "silent"]
|
||||
, "g" : "--global"
|
||||
, "f" : "--force"
|
||||
, "p" : "--parseable"
|
||||
, "l" : "--long"
|
||||
}
|
||||
```
|
||||
|
||||
```bash
|
||||
npm ls -sgflp
|
||||
# just like doing this:
|
||||
npm ls --loglevel silent --global --force --long --parseable
|
||||
```
|
||||
|
||||
## The Rest of the args
|
||||
|
||||
The config object returned by nopt is given a special member called
|
||||
`argv`, which is an object with the following fields:
|
||||
|
||||
* `remain`: The remaining args after all the parsing has occurred.
|
||||
* `original`: The args as they originally appeared.
|
||||
* `cooked`: The args after flags and shorthands are expanded.
|
||||
|
||||
## Slicing
|
||||
|
||||
Node programs are called with more or less the exact argv as it appears
|
||||
in C land, after the v8 and node-specific options have been plucked off.
|
||||
As such, `argv[0]` is always `node` and `argv[1]` is always the
|
||||
JavaScript program being run.
|
||||
|
||||
That's usually not very useful to you. So they're sliced off by
|
||||
default. If you want them, then you can pass in `0` as the last
|
||||
argument, or any other number that you'd like to slice off the start of
|
||||
the list.
|
29
node_modules/nopt/bin/nopt.js
generated
vendored
Executable file
29
node_modules/nopt/bin/nopt.js
generated
vendored
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env node
|
||||
const nopt = require('../lib/nopt')
|
||||
const path = require('path')
|
||||
console.log('parsed', nopt({
|
||||
num: Number,
|
||||
bool: Boolean,
|
||||
help: Boolean,
|
||||
list: Array,
|
||||
'num-list': [Number, Array],
|
||||
'str-list': [String, Array],
|
||||
'bool-list': [Boolean, Array],
|
||||
str: String,
|
||||
clear: Boolean,
|
||||
config: Boolean,
|
||||
length: Number,
|
||||
file: path,
|
||||
}, {
|
||||
s: ['--str', 'astring'],
|
||||
b: ['--bool'],
|
||||
nb: ['--no-bool'],
|
||||
tft: ['--bool-list', '--no-bool-list', '--bool-list', 'true'],
|
||||
'?': ['--help'],
|
||||
h: ['--help'],
|
||||
H: ['--help'],
|
||||
n: ['--num', '125'],
|
||||
c: ['--config'],
|
||||
l: ['--length'],
|
||||
f: ['--file'],
|
||||
}, process.argv, 2))
|
5
node_modules/nopt/lib/debug.js
generated
vendored
Normal file
5
node_modules/nopt/lib/debug.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
/* istanbul ignore next */
|
||||
module.exports = process.env.DEBUG_NOPT || process.env.NOPT_DEBUG
|
||||
// eslint-disable-next-line no-console
|
||||
? (...a) => console.error(...a)
|
||||
: () => {}
|
479
node_modules/nopt/lib/nopt-lib.js
generated
vendored
Normal file
479
node_modules/nopt/lib/nopt-lib.js
generated
vendored
Normal file
|
@ -0,0 +1,479 @@
|
|||
const abbrev = require('abbrev')
|
||||
const debug = require('./debug')
|
||||
const defaultTypeDefs = require('./type-defs')
|
||||
|
||||
const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k)
|
||||
|
||||
const getType = (k, { types, dynamicTypes }) => {
|
||||
let hasType = hasOwn(types, k)
|
||||
let type = types[k]
|
||||
if (!hasType && typeof dynamicTypes === 'function') {
|
||||
const matchedType = dynamicTypes(k)
|
||||
if (matchedType !== undefined) {
|
||||
type = matchedType
|
||||
hasType = true
|
||||
}
|
||||
}
|
||||
return [hasType, type]
|
||||
}
|
||||
|
||||
const isTypeDef = (type, def) => def && type === def
|
||||
const hasTypeDef = (type, def) => def && type.indexOf(def) !== -1
|
||||
const doesNotHaveTypeDef = (type, def) => def && !hasTypeDef(type, def)
|
||||
|
||||
function nopt (args, {
|
||||
types,
|
||||
shorthands,
|
||||
typeDefs,
|
||||
invalidHandler,
|
||||
typeDefault,
|
||||
dynamicTypes,
|
||||
} = {}) {
|
||||
debug(types, shorthands, args, typeDefs)
|
||||
|
||||
const data = {}
|
||||
const argv = {
|
||||
remain: [],
|
||||
cooked: args,
|
||||
original: args.slice(0),
|
||||
}
|
||||
|
||||
parse(args, data, argv.remain, { typeDefs, types, dynamicTypes, shorthands })
|
||||
|
||||
// now data is full
|
||||
clean(data, { types, dynamicTypes, typeDefs, invalidHandler, typeDefault })
|
||||
data.argv = argv
|
||||
|
||||
Object.defineProperty(data.argv, 'toString', {
|
||||
value: function () {
|
||||
return this.original.map(JSON.stringify).join(' ')
|
||||
},
|
||||
enumerable: false,
|
||||
})
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
function clean (data, {
|
||||
types = {},
|
||||
typeDefs = {},
|
||||
dynamicTypes,
|
||||
invalidHandler,
|
||||
typeDefault,
|
||||
} = {}) {
|
||||
const StringType = typeDefs.String?.type
|
||||
const NumberType = typeDefs.Number?.type
|
||||
const ArrayType = typeDefs.Array?.type
|
||||
const BooleanType = typeDefs.Boolean?.type
|
||||
const DateType = typeDefs.Date?.type
|
||||
|
||||
const hasTypeDefault = typeof typeDefault !== 'undefined'
|
||||
if (!hasTypeDefault) {
|
||||
typeDefault = [false, true, null]
|
||||
if (StringType) {
|
||||
typeDefault.push(StringType)
|
||||
}
|
||||
if (ArrayType) {
|
||||
typeDefault.push(ArrayType)
|
||||
}
|
||||
}
|
||||
|
||||
const remove = {}
|
||||
|
||||
Object.keys(data).forEach((k) => {
|
||||
if (k === 'argv') {
|
||||
return
|
||||
}
|
||||
let val = data[k]
|
||||
debug('val=%j', val)
|
||||
const isArray = Array.isArray(val)
|
||||
let [hasType, rawType] = getType(k, { types, dynamicTypes })
|
||||
let type = rawType
|
||||
if (!isArray) {
|
||||
val = [val]
|
||||
}
|
||||
if (!type) {
|
||||
type = typeDefault
|
||||
}
|
||||
if (isTypeDef(type, ArrayType)) {
|
||||
type = typeDefault.concat(ArrayType)
|
||||
}
|
||||
if (!Array.isArray(type)) {
|
||||
type = [type]
|
||||
}
|
||||
|
||||
debug('val=%j', val)
|
||||
debug('types=', type)
|
||||
val = val.map((v) => {
|
||||
// if it's an unknown value, then parse false/true/null/numbers/dates
|
||||
if (typeof v === 'string') {
|
||||
debug('string %j', v)
|
||||
v = v.trim()
|
||||
if ((v === 'null' && ~type.indexOf(null))
|
||||
|| (v === 'true' &&
|
||||
(~type.indexOf(true) || hasTypeDef(type, BooleanType)))
|
||||
|| (v === 'false' &&
|
||||
(~type.indexOf(false) || hasTypeDef(type, BooleanType)))) {
|
||||
v = JSON.parse(v)
|
||||
debug('jsonable %j', v)
|
||||
} else if (hasTypeDef(type, NumberType) && !isNaN(v)) {
|
||||
debug('convert to number', v)
|
||||
v = +v
|
||||
} else if (hasTypeDef(type, DateType) && !isNaN(Date.parse(v))) {
|
||||
debug('convert to date', v)
|
||||
v = new Date(v)
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasType) {
|
||||
if (!hasTypeDefault) {
|
||||
return v
|
||||
}
|
||||
// if the default type has been passed in then we want to validate the
|
||||
// unknown data key instead of bailing out earlier. we also set the raw
|
||||
// type which is passed to the invalid handler so that it can be
|
||||
// determined if during validation if it is unknown vs invalid
|
||||
rawType = typeDefault
|
||||
}
|
||||
|
||||
// allow `--no-blah` to set 'blah' to null if null is allowed
|
||||
if (v === false && ~type.indexOf(null) &&
|
||||
!(~type.indexOf(false) || hasTypeDef(type, BooleanType))) {
|
||||
v = null
|
||||
}
|
||||
|
||||
const d = {}
|
||||
d[k] = v
|
||||
debug('prevalidated val', d, v, rawType)
|
||||
if (!validate(d, k, v, rawType, { typeDefs })) {
|
||||
if (invalidHandler) {
|
||||
invalidHandler(k, v, rawType, data)
|
||||
} else if (invalidHandler !== false) {
|
||||
debug('invalid: ' + k + '=' + v, rawType)
|
||||
}
|
||||
return remove
|
||||
}
|
||||
debug('validated v', d, v, rawType)
|
||||
return d[k]
|
||||
}).filter((v) => v !== remove)
|
||||
|
||||
// if we allow Array specifically, then an empty array is how we
|
||||
// express 'no value here', not null. Allow it.
|
||||
if (!val.length && doesNotHaveTypeDef(type, ArrayType)) {
|
||||
debug('VAL HAS NO LENGTH, DELETE IT', val, k, type.indexOf(ArrayType))
|
||||
delete data[k]
|
||||
} else if (isArray) {
|
||||
debug(isArray, data[k], val)
|
||||
data[k] = val
|
||||
} else {
|
||||
data[k] = val[0]
|
||||
}
|
||||
|
||||
debug('k=%s val=%j', k, val, data[k])
|
||||
})
|
||||
}
|
||||
|
||||
function validate (data, k, val, type, { typeDefs } = {}) {
|
||||
const ArrayType = typeDefs?.Array?.type
|
||||
// arrays are lists of types.
|
||||
if (Array.isArray(type)) {
|
||||
for (let i = 0, l = type.length; i < l; i++) {
|
||||
if (isTypeDef(type[i], ArrayType)) {
|
||||
continue
|
||||
}
|
||||
if (validate(data, k, val, type[i], { typeDefs })) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
delete data[k]
|
||||
return false
|
||||
}
|
||||
|
||||
// an array of anything?
|
||||
if (isTypeDef(type, ArrayType)) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Original comment:
|
||||
// NaN is poisonous. Means that something is not allowed.
|
||||
// New comment: Changing this to an isNaN check breaks a lot of tests.
|
||||
// Something is being assumed here that is not actually what happens in
|
||||
// practice. Fixing it is outside the scope of getting linting to pass in
|
||||
// this repo. Leaving as-is for now.
|
||||
/* eslint-disable-next-line no-self-compare */
|
||||
if (type !== type) {
|
||||
debug('Poison NaN', k, val, type)
|
||||
delete data[k]
|
||||
return false
|
||||
}
|
||||
|
||||
// explicit list of values
|
||||
if (val === type) {
|
||||
debug('Explicitly allowed %j', val)
|
||||
data[k] = val
|
||||
return true
|
||||
}
|
||||
|
||||
// now go through the list of typeDefs, validate against each one.
|
||||
let ok = false
|
||||
const types = Object.keys(typeDefs)
|
||||
for (let i = 0, l = types.length; i < l; i++) {
|
||||
debug('test type %j %j %j', k, val, types[i])
|
||||
const t = typeDefs[types[i]]
|
||||
if (t && (
|
||||
(type && type.name && t.type && t.type.name) ?
|
||||
(type.name === t.type.name) :
|
||||
(type === t.type)
|
||||
)) {
|
||||
const d = {}
|
||||
ok = t.validate(d, k, val) !== false
|
||||
val = d[k]
|
||||
if (ok) {
|
||||
data[k] = val
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
debug('OK? %j (%j %j %j)', ok, k, val, types[types.length - 1])
|
||||
|
||||
if (!ok) {
|
||||
delete data[k]
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
function parse (args, data, remain, {
|
||||
types = {},
|
||||
typeDefs = {},
|
||||
shorthands = {},
|
||||
dynamicTypes,
|
||||
} = {}) {
|
||||
const StringType = typeDefs.String?.type
|
||||
const NumberType = typeDefs.Number?.type
|
||||
const ArrayType = typeDefs.Array?.type
|
||||
const BooleanType = typeDefs.Boolean?.type
|
||||
|
||||
debug('parse', args, data, remain)
|
||||
|
||||
const abbrevs = abbrev(Object.keys(types))
|
||||
debug('abbrevs=%j', abbrevs)
|
||||
const shortAbbr = abbrev(Object.keys(shorthands))
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
let arg = args[i]
|
||||
debug('arg', arg)
|
||||
|
||||
if (arg.match(/^-{2,}$/)) {
|
||||
// done with keys.
|
||||
// the rest are args.
|
||||
remain.push.apply(remain, args.slice(i + 1))
|
||||
args[i] = '--'
|
||||
break
|
||||
}
|
||||
let hadEq = false
|
||||
if (arg.charAt(0) === '-' && arg.length > 1) {
|
||||
const at = arg.indexOf('=')
|
||||
if (at > -1) {
|
||||
hadEq = true
|
||||
const v = arg.slice(at + 1)
|
||||
arg = arg.slice(0, at)
|
||||
args.splice(i, 1, arg, v)
|
||||
}
|
||||
|
||||
// see if it's a shorthand
|
||||
// if so, splice and back up to re-parse it.
|
||||
const shRes = resolveShort(arg, shortAbbr, abbrevs, { shorthands })
|
||||
debug('arg=%j shRes=%j', arg, shRes)
|
||||
if (shRes) {
|
||||
args.splice.apply(args, [i, 1].concat(shRes))
|
||||
if (arg !== shRes[0]) {
|
||||
i--
|
||||
continue
|
||||
}
|
||||
}
|
||||
arg = arg.replace(/^-+/, '')
|
||||
let no = null
|
||||
while (arg.toLowerCase().indexOf('no-') === 0) {
|
||||
no = !no
|
||||
arg = arg.slice(3)
|
||||
}
|
||||
|
||||
if (abbrevs[arg]) {
|
||||
arg = abbrevs[arg]
|
||||
}
|
||||
|
||||
let [hasType, argType] = getType(arg, { types, dynamicTypes })
|
||||
let isTypeArray = Array.isArray(argType)
|
||||
if (isTypeArray && argType.length === 1) {
|
||||
isTypeArray = false
|
||||
argType = argType[0]
|
||||
}
|
||||
|
||||
let isArray = isTypeDef(argType, ArrayType) ||
|
||||
isTypeArray && hasTypeDef(argType, ArrayType)
|
||||
|
||||
// allow unknown things to be arrays if specified multiple times.
|
||||
if (!hasType && hasOwn(data, arg)) {
|
||||
if (!Array.isArray(data[arg])) {
|
||||
data[arg] = [data[arg]]
|
||||
}
|
||||
isArray = true
|
||||
}
|
||||
|
||||
let val
|
||||
let la = args[i + 1]
|
||||
|
||||
const isBool = typeof no === 'boolean' ||
|
||||
isTypeDef(argType, BooleanType) ||
|
||||
isTypeArray && hasTypeDef(argType, BooleanType) ||
|
||||
(typeof argType === 'undefined' && !hadEq) ||
|
||||
(la === 'false' &&
|
||||
(argType === null ||
|
||||
isTypeArray && ~argType.indexOf(null)))
|
||||
|
||||
if (isBool) {
|
||||
// just set and move along
|
||||
val = !no
|
||||
// however, also support --bool true or --bool false
|
||||
if (la === 'true' || la === 'false') {
|
||||
val = JSON.parse(la)
|
||||
la = null
|
||||
if (no) {
|
||||
val = !val
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
// also support "foo":[Boolean, "bar"] and "--foo bar"
|
||||
if (isTypeArray && la) {
|
||||
if (~argType.indexOf(la)) {
|
||||
// an explicit type
|
||||
val = la
|
||||
i++
|
||||
} else if (la === 'null' && ~argType.indexOf(null)) {
|
||||
// null allowed
|
||||
val = null
|
||||
i++
|
||||
} else if (!la.match(/^-{2,}[^-]/) &&
|
||||
!isNaN(la) &&
|
||||
hasTypeDef(argType, NumberType)) {
|
||||
// number
|
||||
val = +la
|
||||
i++
|
||||
} else if (!la.match(/^-[^-]/) && hasTypeDef(argType, StringType)) {
|
||||
// string
|
||||
val = la
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
if (isArray) {
|
||||
(data[arg] = data[arg] || []).push(val)
|
||||
} else {
|
||||
data[arg] = val
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if (isTypeDef(argType, StringType)) {
|
||||
if (la === undefined) {
|
||||
la = ''
|
||||
} else if (la.match(/^-{1,2}[^-]+/)) {
|
||||
la = ''
|
||||
i--
|
||||
}
|
||||
}
|
||||
|
||||
if (la && la.match(/^-{2,}$/)) {
|
||||
la = undefined
|
||||
i--
|
||||
}
|
||||
|
||||
val = la === undefined ? true : la
|
||||
if (isArray) {
|
||||
(data[arg] = data[arg] || []).push(val)
|
||||
} else {
|
||||
data[arg] = val
|
||||
}
|
||||
|
||||
i++
|
||||
continue
|
||||
}
|
||||
remain.push(arg)
|
||||
}
|
||||
}
|
||||
|
||||
const SINGLES = Symbol('singles')
|
||||
const singleCharacters = (arg, shorthands) => {
|
||||
let singles = shorthands[SINGLES]
|
||||
if (!singles) {
|
||||
singles = Object.keys(shorthands).filter((s) => s.length === 1).reduce((l, r) => {
|
||||
l[r] = true
|
||||
return l
|
||||
}, {})
|
||||
shorthands[SINGLES] = singles
|
||||
debug('shorthand singles', singles)
|
||||
}
|
||||
const chrs = arg.split('').filter((c) => singles[c])
|
||||
return chrs.join('') === arg ? chrs : null
|
||||
}
|
||||
|
||||
function resolveShort (arg, ...rest) {
|
||||
const { types = {}, shorthands = {} } = rest.length ? rest.pop() : {}
|
||||
const shortAbbr = rest[0] ?? abbrev(Object.keys(shorthands))
|
||||
const abbrevs = rest[1] ?? abbrev(Object.keys(types))
|
||||
|
||||
// handle single-char shorthands glommed together, like
|
||||
// npm ls -glp, but only if there is one dash, and only if
|
||||
// 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) {
|
||||
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
|
||||
const chrs = singleCharacters(arg, shorthands)
|
||||
if (chrs) {
|
||||
return chrs.map((c) => shorthands[c]).reduce((l, r) => 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]) {
|
||||
arg = shortAbbr[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]
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
nopt,
|
||||
clean,
|
||||
parse,
|
||||
validate,
|
||||
resolveShort,
|
||||
typeDefs: defaultTypeDefs,
|
||||
}
|
30
node_modules/nopt/lib/nopt.js
generated
vendored
Normal file
30
node_modules/nopt/lib/nopt.js
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
const lib = require('./nopt-lib')
|
||||
const defaultTypeDefs = require('./type-defs')
|
||||
|
||||
// This is the version of nopt's API that requires setting typeDefs and invalidHandler
|
||||
// on the required `nopt` object since it is a singleton. To not do a breaking change
|
||||
// an API that requires all options be passed in is located in `nopt-lib.js` and
|
||||
// exported here as lib.
|
||||
// TODO(breaking): make API only work in non-singleton mode
|
||||
|
||||
module.exports = exports = nopt
|
||||
exports.clean = clean
|
||||
exports.typeDefs = defaultTypeDefs
|
||||
exports.lib = lib
|
||||
|
||||
function nopt (types, shorthands, args = process.argv, slice = 2) {
|
||||
return lib.nopt(args.slice(slice), {
|
||||
types: types || {},
|
||||
shorthands: shorthands || {},
|
||||
typeDefs: exports.typeDefs,
|
||||
invalidHandler: exports.invalidHandler,
|
||||
})
|
||||
}
|
||||
|
||||
function clean (data, types, typeDefs = exports.typeDefs) {
|
||||
return lib.clean(data, {
|
||||
types: types || {},
|
||||
typeDefs,
|
||||
invalidHandler: exports.invalidHandler,
|
||||
})
|
||||
}
|
91
node_modules/nopt/lib/type-defs.js
generated
vendored
Normal file
91
node_modules/nopt/lib/type-defs.js
generated
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
const url = require('url')
|
||||
const path = require('path')
|
||||
const Stream = require('stream').Stream
|
||||
const os = require('os')
|
||||
const debug = require('./debug')
|
||||
|
||||
function validateString (data, k, val) {
|
||||
data[k] = String(val)
|
||||
}
|
||||
|
||||
function validatePath (data, k, val) {
|
||||
if (val === true) {
|
||||
return false
|
||||
}
|
||||
if (val === null) {
|
||||
return true
|
||||
}
|
||||
|
||||
val = String(val)
|
||||
|
||||
const isWin = process.platform === 'win32'
|
||||
const homePattern = isWin ? /^~(\/|\\)/ : /^~\//
|
||||
const home = os.homedir()
|
||||
|
||||
if (home && val.match(homePattern)) {
|
||||
data[k] = path.resolve(home, val.slice(2))
|
||||
} else {
|
||||
data[k] = path.resolve(val)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function validateNumber (data, k, val) {
|
||||
debug('validate Number %j %j %j', k, val, isNaN(val))
|
||||
if (isNaN(val)) {
|
||||
return false
|
||||
}
|
||||
data[k] = +val
|
||||
}
|
||||
|
||||
function validateDate (data, k, val) {
|
||||
const s = Date.parse(val)
|
||||
debug('validate Date %j %j %j', k, val, s)
|
||||
if (isNaN(s)) {
|
||||
return false
|
||||
}
|
||||
data[k] = new Date(val)
|
||||
}
|
||||
|
||||
function validateBoolean (data, k, val) {
|
||||
if (typeof val === 'string') {
|
||||
if (!isNaN(val)) {
|
||||
val = !!(+val)
|
||||
} else if (val === 'null' || val === 'false') {
|
||||
val = false
|
||||
} else {
|
||||
val = true
|
||||
}
|
||||
} else {
|
||||
val = !!val
|
||||
}
|
||||
data[k] = val
|
||||
}
|
||||
|
||||
function validateUrl (data, k, val) {
|
||||
// Changing this would be a breaking change in the npm cli
|
||||
/* eslint-disable-next-line node/no-deprecated-api */
|
||||
val = url.parse(String(val))
|
||||
if (!val.host) {
|
||||
return false
|
||||
}
|
||||
data[k] = val.href
|
||||
}
|
||||
|
||||
function validateStream (data, k, val) {
|
||||
if (!(val instanceof Stream)) {
|
||||
return false
|
||||
}
|
||||
data[k] = val
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
String: { type: String, validate: validateString },
|
||||
Boolean: { type: Boolean, validate: validateBoolean },
|
||||
url: { type: url, validate: validateUrl },
|
||||
Number: { type: Number, validate: validateNumber },
|
||||
path: { type: path, validate: validatePath },
|
||||
Stream: { type: Stream, validate: validateStream },
|
||||
Date: { type: Date, validate: validateDate },
|
||||
Array: { type: Array },
|
||||
}
|
51
node_modules/nopt/package.json
generated
vendored
Normal file
51
node_modules/nopt/package.json
generated
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"name": "nopt",
|
||||
"version": "7.2.1",
|
||||
"description": "Option parsing for Node, supporting types, shorthands, etc. Used by npm.",
|
||||
"author": "GitHub Inc.",
|
||||
"main": "lib/nopt.js",
|
||||
"scripts": {
|
||||
"test": "tap",
|
||||
"lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
|
||||
"postlint": "template-oss-check",
|
||||
"template-oss-apply": "template-oss-apply --force",
|
||||
"lintfix": "npm run lint -- --fix",
|
||||
"snap": "tap",
|
||||
"posttest": "npm run lint"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/npm/nopt.git"
|
||||
},
|
||||
"bin": {
|
||||
"nopt": "bin/nopt.js"
|
||||
},
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"abbrev": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^4.0.0",
|
||||
"@npmcli/template-oss": "4.22.0",
|
||||
"tap": "^16.3.0"
|
||||
},
|
||||
"tap": {
|
||||
"nyc-arg": [
|
||||
"--exclude",
|
||||
"tap-snapshots/**"
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"bin/",
|
||||
"lib/"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"windowsCI": false,
|
||||
"version": "4.22.0",
|
||||
"publish": true
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue