initial
This commit is contained in:
38
node_modules/command-line-args/test/alias.js
generated
vendored
Normal file
38
node_modules/command-line-args/test/alias.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('alias: one string alias', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'verbose', alias: 'v' }
|
||||
]
|
||||
const argv = [ '-v' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
verbose: null
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('alias: one boolean alias', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'dry-run', alias: 'd', type: Boolean }
|
||||
]
|
||||
const argv = [ '-d' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
'dry-run': true
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('alias: one boolean, one string', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'verbose', alias: 'v', type: Boolean },
|
||||
{ name: 'colour', alias: 'c' }
|
||||
]
|
||||
const argv = [ '-v', '-c' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
verbose: true,
|
||||
colour: null
|
||||
})
|
||||
})
|
44
node_modules/command-line-args/test/ambiguous-input.js
generated
vendored
Normal file
44
node_modules/command-line-args/test/ambiguous-input.js
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('ambiguous input: value looks like an option 1', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colour', type: String, alias: 'c' }
|
||||
]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv: [ '-c', 'red' ] }), {
|
||||
colour: 'red'
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('ambiguous input: value looks like an option 2', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colour', type: String, alias: 'c' }
|
||||
]
|
||||
const argv = [ '--colour', '--red' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'UNKNOWN_OPTION'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('ambiguous input: value looks like an option 3', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colour', type: String, alias: 'c' }
|
||||
]
|
||||
a.doesNotThrow(function () {
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--colour=--red' ] })
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('ambiguous input: value looks like an option 4', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colour', type: String, alias: 'c' }
|
||||
]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv: [ '--colour=--red' ] }), {
|
||||
colour: '--red'
|
||||
})
|
||||
})
|
61
node_modules/command-line-args/test/bad-input.js
generated
vendored
Normal file
61
node_modules/command-line-args/test/bad-input.js
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('bad-input: missing option value should be null', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colour', type: String },
|
||||
{ name: 'files' }
|
||||
]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv: [ '--colour' ] }), {
|
||||
colour: null
|
||||
})
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv: [ '--colour', '--files', 'yeah' ] }), {
|
||||
colour: null,
|
||||
files: 'yeah'
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('bad-input: handles arrays with relative paths', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colours', type: String, multiple: true }
|
||||
]
|
||||
const argv = [ '--colours', '../what', '../ever' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
colours: [ '../what', '../ever' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('bad-input: empty string added to unknown values', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: String },
|
||||
{ name: 'two', type: Number },
|
||||
{ name: 'three', type: Number, multiple: true },
|
||||
{ name: 'four', type: String },
|
||||
{ name: 'five', type: Boolean }
|
||||
]
|
||||
const argv = [ '--one', '', '', '--two', '0', '--three=', '', '--four=', '--five=' ]
|
||||
a.throws(() => {
|
||||
commandLineArgs(optionDefinitions, { argv })
|
||||
})
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv, partial: true }), {
|
||||
one: '',
|
||||
two: 0,
|
||||
three: [ 0, 0 ],
|
||||
four: '',
|
||||
five: true,
|
||||
_unknown: [ '', '--five=' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('bad-input: non-strings in argv', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Number }
|
||||
]
|
||||
const argv = [ '--one', 1 ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, { one: 1 })
|
||||
})
|
78
node_modules/command-line-args/test/camel-case.js
generated
vendored
Normal file
78
node_modules/command-line-args/test/camel-case.js
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('camel-case: regular', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one-two' },
|
||||
{ name: 'three', type: Boolean }
|
||||
]
|
||||
const argv = [ '--one-two', '1', '--three' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv, camelCase: true })
|
||||
a.deepStrictEqual(result, {
|
||||
oneTwo: '1',
|
||||
three: true
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('camel-case: grouped', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one-one', group: 'a' },
|
||||
{ name: 'two-two', group: 'a' },
|
||||
{ name: 'three-three', group: 'b', type: Boolean },
|
||||
{ name: 'four-four' }
|
||||
]
|
||||
const argv = [ '--one-one', '1', '--two-two', '2', '--three-three', '--four-four', '4' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv, camelCase: true })
|
||||
a.deepStrictEqual(result, {
|
||||
a: {
|
||||
oneOne: '1',
|
||||
twoTwo: '2'
|
||||
},
|
||||
b: {
|
||||
threeThree: true
|
||||
},
|
||||
_all: {
|
||||
oneOne: '1',
|
||||
twoTwo: '2',
|
||||
threeThree: true,
|
||||
fourFour: '4'
|
||||
},
|
||||
_none: {
|
||||
fourFour: '4'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('camel-case: grouped with unknowns', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one-one', group: 'a' },
|
||||
{ name: 'two-two', group: 'a' },
|
||||
{ name: 'three-three', group: 'b', type: Boolean },
|
||||
{ name: 'four-four' }
|
||||
]
|
||||
const argv = [ '--one-one', '1', '--two-two', '2', '--three-three', '--four-four', '4', '--five' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv, camelCase: true, partial: true })
|
||||
a.deepStrictEqual(result, {
|
||||
a: {
|
||||
oneOne: '1',
|
||||
twoTwo: '2'
|
||||
},
|
||||
b: {
|
||||
threeThree: true
|
||||
},
|
||||
_all: {
|
||||
oneOne: '1',
|
||||
twoTwo: '2',
|
||||
threeThree: true,
|
||||
fourFour: '4'
|
||||
},
|
||||
_none: {
|
||||
fourFour: '4'
|
||||
},
|
||||
_unknown: [ '--five' ]
|
||||
})
|
||||
})
|
55
node_modules/command-line-args/test/default-option.js
generated
vendored
Normal file
55
node_modules/command-line-args/test/default-option.js
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('defaultOption: multiple string', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'files', defaultOption: true, multiple: true }
|
||||
]
|
||||
const argv = [ 'file1', 'file2' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
files: [ 'file1', 'file2' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('defaultOption: after a boolean', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', type: Boolean },
|
||||
{ name: 'two', defaultOption: true }
|
||||
]
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one', 'sfsgf' ] }),
|
||||
{ one: true, two: 'sfsgf' }
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('defaultOption: multiple-defaultOption values spread out', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one' },
|
||||
{ name: 'two' },
|
||||
{ name: 'files', defaultOption: true, multiple: true }
|
||||
]
|
||||
const argv = [ '--one', '1', 'file1', 'file2', '--two', '2' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
one: '1',
|
||||
two: '2',
|
||||
files: [ 'file1', 'file2' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('defaultOption: multiple-defaultOption values spread out 2', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean },
|
||||
{ name: 'two' },
|
||||
{ name: 'files', defaultOption: true, multiple: true }
|
||||
]
|
||||
const argv = [ 'file0', '--one', 'file1', '--files', 'file2', '--two', '2', 'file3' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
one: true,
|
||||
two: '2',
|
||||
files: [ 'file0', 'file1', 'file2', 'file3' ]
|
||||
})
|
||||
})
|
154
node_modules/command-line-args/test/default-value.js
generated
vendored
Normal file
154
node_modules/command-line-args/test/default-value.js
generated
vendored
Normal file
@ -0,0 +1,154 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('default value', function () {
|
||||
const defs = [
|
||||
{ name: 'one' },
|
||||
{ name: 'two', defaultValue: 'two' }
|
||||
]
|
||||
const argv = [ '--one', '1' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
one: '1',
|
||||
two: 'two'
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('default value 2', function () {
|
||||
const defs = [ { name: 'two', defaultValue: 'two' } ]
|
||||
const argv = []
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: 'two' })
|
||||
})
|
||||
|
||||
runner.test('default value 3', function () {
|
||||
const defs = [ { name: 'two', defaultValue: 'two' } ]
|
||||
const argv = [ '--two', 'zwei' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: 'zwei' })
|
||||
})
|
||||
|
||||
runner.test('default value 4', function () {
|
||||
const defs = [ { name: 'two', multiple: true, defaultValue: [ 'two', 'zwei' ] } ]
|
||||
const argv = [ '--two', 'duo' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: [ 'duo' ] })
|
||||
})
|
||||
|
||||
runner.test('default value 5', function () {
|
||||
const defs = [
|
||||
{ name: 'two', multiple: true, defaultValue: ['two', 'zwei'] }
|
||||
]
|
||||
const argv = []
|
||||
const result = commandLineArgs(defs, { argv })
|
||||
a.deepStrictEqual(result, { two: [ 'two', 'zwei' ] })
|
||||
})
|
||||
|
||||
runner.test('default value: array as defaultOption', function () {
|
||||
const defs = [
|
||||
{ name: 'two', multiple: true, defaultValue: ['two', 'zwei'], defaultOption: true }
|
||||
]
|
||||
const argv = [ 'duo' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: [ 'duo' ] })
|
||||
})
|
||||
|
||||
runner.test('default value: falsy default values', function () {
|
||||
const defs = [
|
||||
{ name: 'one', defaultValue: 0 },
|
||||
{ name: 'two', defaultValue: false }
|
||||
]
|
||||
|
||||
const argv = []
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
one: 0,
|
||||
two: false
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('default value: is arrayifed if multiple set', function () {
|
||||
const defs = [
|
||||
{ name: 'one', defaultValue: 0, multiple: true }
|
||||
]
|
||||
|
||||
let argv = []
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
one: [ 0 ]
|
||||
})
|
||||
argv = [ '--one', '2' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
one: [ '2' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('default value: combined with defaultOption', function () {
|
||||
const defs = [
|
||||
{ name: 'path', defaultOption: true, defaultValue: './' }
|
||||
]
|
||||
|
||||
let argv = [ '--path', 'test' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: 'test'
|
||||
})
|
||||
argv = [ 'test' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: 'test'
|
||||
})
|
||||
argv = [ ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: './'
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('default value: combined with multiple and defaultOption', function () {
|
||||
const defs = [
|
||||
{ name: 'path', multiple: true, defaultOption: true, defaultValue: './' }
|
||||
]
|
||||
|
||||
let argv = [ '--path', 'test1', 'test2' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: [ 'test1', 'test2' ]
|
||||
})
|
||||
argv = [ '--path', 'test' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: [ 'test' ]
|
||||
})
|
||||
argv = [ 'test1', 'test2' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: [ 'test1', 'test2' ]
|
||||
})
|
||||
argv = [ 'test' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: [ 'test' ]
|
||||
})
|
||||
argv = [ ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: [ './' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('default value: array default combined with multiple and defaultOption', function () {
|
||||
const defs = [
|
||||
{ name: 'path', multiple: true, defaultOption: true, defaultValue: [ './' ] }
|
||||
]
|
||||
|
||||
let argv = [ '--path', 'test1', 'test2' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: [ 'test1', 'test2' ]
|
||||
})
|
||||
argv = [ '--path', 'test' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: [ 'test' ]
|
||||
})
|
||||
argv = [ 'test1', 'test2' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: [ 'test1', 'test2' ]
|
||||
})
|
||||
argv = [ 'test' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: [ 'test' ]
|
||||
})
|
||||
argv = [ ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
path: [ './' ]
|
||||
})
|
||||
})
|
28
node_modules/command-line-args/test/detect-process-argv.js
generated
vendored
Normal file
28
node_modules/command-line-args/test/detect-process-argv.js
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('detect process.argv: should automatically remove first two argv items', function () {
|
||||
process.argv = [ 'node', 'filename', '--one', 'eins' ]
|
||||
a.deepStrictEqual(commandLineArgs({ name: 'one' }), {
|
||||
one: 'eins'
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('detect process.argv: should automatically remove first two argv items 2', function () {
|
||||
process.argv = [ 'node', 'filename', '--one', 'eins' ]
|
||||
a.deepStrictEqual(commandLineArgs({ name: 'one' }, { argv: process.argv }), {
|
||||
one: 'eins'
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('process.argv is left untouched', function () {
|
||||
process.argv = [ 'node', 'filename', '--one', 'eins' ]
|
||||
a.deepStrictEqual(commandLineArgs({ name: 'one' }), {
|
||||
one: 'eins'
|
||||
})
|
||||
a.deepStrictEqual(process.argv, [ 'node', 'filename', '--one', 'eins' ])
|
||||
})
|
50
node_modules/command-line-args/test/exceptions-already-set.js
generated
vendored
Normal file
50
node_modules/command-line-args/test/exceptions-already-set.js
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('exceptions-already-set: long option', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean }
|
||||
]
|
||||
const argv = [ '--one', '--one' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'ALREADY_SET' && err.optionName === 'one'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('exceptions-already-set: short option', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean, alias: 'o' }
|
||||
]
|
||||
const argv = [ '--one', '-o' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'ALREADY_SET' && err.optionName === 'one'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('exceptions-already-set: --option=value', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one' }
|
||||
]
|
||||
const argv = [ '--one=1', '--one=1' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'ALREADY_SET' && err.optionName === 'one'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('exceptions-already-set: combined short option', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean, alias: 'o' }
|
||||
]
|
||||
const argv = [ '-oo' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'ALREADY_SET' && err.optionName === 'one'
|
||||
)
|
||||
})
|
131
node_modules/command-line-args/test/exceptions-invalid-definition.js
generated
vendored
Normal file
131
node_modules/command-line-args/test/exceptions-invalid-definition.js
generated
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('err-invalid-definition: throws when no definition.name specified', function () {
|
||||
const optionDefinitions = [
|
||||
{ something: 'one' },
|
||||
{ something: 'two' }
|
||||
]
|
||||
const argv = [ '--one', '--two' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'INVALID_DEFINITIONS'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: throws if dev set a numeric alias', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colours', alias: '1' }
|
||||
]
|
||||
const argv = [ '--colours', 'red' ]
|
||||
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'INVALID_DEFINITIONS'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: throws if dev set an alias of "-"', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colours', alias: '-' }
|
||||
]
|
||||
const argv = [ '--colours', 'red' ]
|
||||
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'INVALID_DEFINITIONS'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: multi-character alias', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', alias: 'aa' }
|
||||
]
|
||||
const argv = [ '--one', 'red' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'INVALID_DEFINITIONS'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: invalid type values 1', function () {
|
||||
const argv = [ '--one', 'something' ]
|
||||
a.throws(
|
||||
() => commandLineArgs([ { name: 'one', type: 'string' } ], { argv }),
|
||||
err => err.name === 'INVALID_DEFINITIONS'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: invalid type values 2', function () {
|
||||
const argv = [ '--one', 'something' ]
|
||||
a.throws(
|
||||
() => commandLineArgs([ { name: 'one', type: 234 } ], { argv }),
|
||||
err => err.name === 'INVALID_DEFINITIONS'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: invalid type values 3', function () {
|
||||
const argv = [ '--one', 'something' ]
|
||||
a.throws(
|
||||
() => commandLineArgs([ { name: 'one', type: {} } ], { argv }),
|
||||
err => err.name === 'INVALID_DEFINITIONS'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: invalid type values 4', function () {
|
||||
const argv = [ '--one', 'something' ]
|
||||
a.doesNotThrow(function () {
|
||||
commandLineArgs([ { name: 'one', type: function () {} } ], { argv })
|
||||
}, /invalid/i)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: duplicate name', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colours' },
|
||||
{ name: 'colours' }
|
||||
]
|
||||
const argv = [ '--colours', 'red' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'INVALID_DEFINITIONS'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: duplicate alias', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', alias: 'a' },
|
||||
{ name: 'two', alias: 'a' }
|
||||
]
|
||||
const argv = [ '--one', 'red' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'INVALID_DEFINITIONS'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: multiple defaultOption', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', defaultOption: true },
|
||||
{ name: 'two', defaultOption: true }
|
||||
]
|
||||
const argv = [ '--one', 'red' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'INVALID_DEFINITIONS'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-defaultOption: defaultOption on a Boolean type', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean, defaultOption: true }
|
||||
]
|
||||
const argv = [ '--one', 'red' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'INVALID_DEFINITIONS'
|
||||
)
|
||||
})
|
91
node_modules/command-line-args/test/exceptions-unknowns.js
generated
vendored
Normal file
91
node_modules/command-line-args/test/exceptions-unknowns.js
generated
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('exceptions-unknowns: unknown option', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Number }
|
||||
]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv: [ '--one', '--two' ] }),
|
||||
err => err.name === 'UNKNOWN_OPTION' && err.optionName === '--two'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('exceptions-unknowns: 1 unknown option, 1 unknown value', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Number }
|
||||
]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv: [ '--one', '2', '--two', 'two' ] }),
|
||||
err => err.name === 'UNKNOWN_OPTION' && err.optionName === '--two'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('exceptions-unknowns: unknown alias', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Number }
|
||||
]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv: [ '-a', '2' ] }),
|
||||
err => err.name === 'UNKNOWN_OPTION' && err.optionName === '-a'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('exceptions-unknowns: unknown combined aliases', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Number }
|
||||
]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv: [ '-sdf' ] }),
|
||||
err => err.name === 'UNKNOWN_OPTION' && err.optionName === '-s'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('exceptions-unknowns: unknown value', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one' }
|
||||
]
|
||||
const argv = [ '--one', 'arg1', 'arg2' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'UNKNOWN_VALUE' && err.value === 'arg2'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('exceptions-unknowns: unknown value with singular defaultOption', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', defaultOption: true }
|
||||
]
|
||||
const argv = [ 'arg1', 'arg2' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'UNKNOWN_VALUE' && err.value === 'arg2'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('exceptions-unknowns: no unknown value exception with multiple defaultOption', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', defaultOption: true, multiple: true }
|
||||
]
|
||||
const argv = [ 'arg1', 'arg2' ]
|
||||
a.doesNotThrow(() => {
|
||||
commandLineArgs(optionDefinitions, { argv })
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('exceptions-unknowns: non-multiple defaultOption should take first value 2', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'file', defaultOption: true },
|
||||
{ name: 'one', type: Boolean },
|
||||
{ name: 'two', type: Boolean }
|
||||
]
|
||||
const argv = [ '--two', 'file1', '--one', 'file2' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'UNKNOWN_VALUE' && err.value === 'file2'
|
||||
)
|
||||
})
|
174
node_modules/command-line-args/test/grouping.js
generated
vendored
Normal file
174
node_modules/command-line-args/test/grouping.js
generated
vendored
Normal file
@ -0,0 +1,174 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('groups', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', group: 'a' },
|
||||
{ name: 'two', group: 'a' },
|
||||
{ name: 'three', group: 'b' }
|
||||
]
|
||||
const argv = [ '--one', '1', '--two', '2', '--three', '3' ]
|
||||
const output = commandLineArgs(definitions, { argv })
|
||||
a.deepStrictEqual(output, {
|
||||
a: {
|
||||
one: '1',
|
||||
two: '2'
|
||||
},
|
||||
b: {
|
||||
three: '3'
|
||||
},
|
||||
_all: {
|
||||
one: '1',
|
||||
two: '2',
|
||||
three: '3'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('groups: multiple and _none', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', group: ['a', 'f'] },
|
||||
{ name: 'two', group: ['a', 'g'] },
|
||||
{ name: 'three' }
|
||||
]
|
||||
|
||||
a.deepStrictEqual(commandLineArgs(definitions, { argv: [ '--one', '1', '--two', '2', '--three', '3' ] }), {
|
||||
a: {
|
||||
one: '1',
|
||||
two: '2'
|
||||
},
|
||||
f: {
|
||||
one: '1'
|
||||
},
|
||||
g: {
|
||||
two: '2'
|
||||
},
|
||||
_none: {
|
||||
three: '3'
|
||||
},
|
||||
_all: {
|
||||
one: '1',
|
||||
two: '2',
|
||||
three: '3'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('groups: nothing set', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', group: 'a' },
|
||||
{ name: 'two', group: 'a' },
|
||||
{ name: 'three', group: 'b' }
|
||||
]
|
||||
const argv = [ ]
|
||||
const output = commandLineArgs(definitions, { argv })
|
||||
a.deepStrictEqual(output, {
|
||||
a: {},
|
||||
b: {},
|
||||
_all: {}
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('groups: nothing set with one ungrouped', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', group: 'a' },
|
||||
{ name: 'two', group: 'a' },
|
||||
{ name: 'three' }
|
||||
]
|
||||
const argv = [ ]
|
||||
const output = commandLineArgs(definitions, { argv })
|
||||
a.deepStrictEqual(output, {
|
||||
a: {},
|
||||
_all: {}
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('groups: two ungrouped, one set', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', group: 'a' },
|
||||
{ name: 'two', group: 'a' },
|
||||
{ name: 'three' },
|
||||
{ name: 'four' }
|
||||
]
|
||||
const argv = [ '--three', '3' ]
|
||||
const output = commandLineArgs(definitions, { argv })
|
||||
a.deepStrictEqual(output, {
|
||||
a: {},
|
||||
_all: { three: '3' },
|
||||
_none: { three: '3' }
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('groups: two ungrouped, both set', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', group: 'a' },
|
||||
{ name: 'two', group: 'a' },
|
||||
{ name: 'three' },
|
||||
{ name: 'four' }
|
||||
]
|
||||
const argv = [ '--three', '3', '--four', '4' ]
|
||||
const output = commandLineArgs(definitions, { argv })
|
||||
a.deepStrictEqual(output, {
|
||||
a: {},
|
||||
_all: { three: '3', four: '4' },
|
||||
_none: { three: '3', four: '4' }
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('groups: with partial', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', group: 'a' },
|
||||
{ name: 'two', group: 'a' },
|
||||
{ name: 'three', group: 'b' }
|
||||
]
|
||||
const argv = [ '--one', '1', '--two', '2', '--three', '3', 'ham', '--cheese' ]
|
||||
a.deepStrictEqual(commandLineArgs(definitions, { argv, partial: true }), {
|
||||
a: {
|
||||
one: '1',
|
||||
two: '2'
|
||||
},
|
||||
b: {
|
||||
three: '3'
|
||||
},
|
||||
_all: {
|
||||
one: '1',
|
||||
two: '2',
|
||||
three: '3'
|
||||
},
|
||||
_unknown: [ 'ham', '--cheese' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: with partial, multiple groups and _none', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', group: ['a', 'f'] },
|
||||
{ name: 'two', group: ['a', 'g'] },
|
||||
{ name: 'three' }
|
||||
]
|
||||
const argv = [ '--cheese', '--one', '1', 'ham', '--two', '2', '--three', '3', '-c' ]
|
||||
a.deepStrictEqual(commandLineArgs(definitions, { argv, partial: true }), {
|
||||
a: {
|
||||
one: '1',
|
||||
two: '2'
|
||||
},
|
||||
f: {
|
||||
one: '1'
|
||||
},
|
||||
g: {
|
||||
two: '2'
|
||||
},
|
||||
_none: {
|
||||
three: '3'
|
||||
},
|
||||
_all: {
|
||||
one: '1',
|
||||
two: '2',
|
||||
three: '3'
|
||||
},
|
||||
_unknown: [ '--cheese', 'ham', '-c' ]
|
||||
})
|
||||
})
|
366
node_modules/command-line-args/test/internals/argv-parser.js
generated
vendored
Normal file
366
node_modules/command-line-args/test/internals/argv-parser.js
generated
vendored
Normal file
@ -0,0 +1,366 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const a = require('assert')
|
||||
const runner = new TestRunner()
|
||||
const ArgvParser = require('../../lib/argv-parser')
|
||||
|
||||
runner.test('argv-parser: long option, string', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one' }
|
||||
]
|
||||
const argv = [ '--one', '1' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: long option, string repeated', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one' }
|
||||
]
|
||||
const argv = [ '--one', '1', '--one', '2' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(result[2].def)
|
||||
a.ok(result[3].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' },
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '2', name: 'one', value: '2' }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: long option, string multiple', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', multiple: true }
|
||||
]
|
||||
const argv = [ '--one', '1', '2' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(result[2].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' },
|
||||
{ event: 'set', arg: '2', name: 'one', value: '2' }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: long option, string multiple then boolean', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', multiple: true },
|
||||
{ name: 'two', type: Boolean }
|
||||
]
|
||||
const argv = [ '--one', '1', '2', '--two' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(result[2].def)
|
||||
a.ok(result[3].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' },
|
||||
{ event: 'set', arg: '2', name: 'one', value: '2' },
|
||||
{ event: 'set', arg: '--two', name: 'two', value: true }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: long option, boolean', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean }
|
||||
]
|
||||
const argv = [ '--one', '1' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(!result[1].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '--one', name: 'one', value: true },
|
||||
{ event: 'unknown_value', arg: '1', name: '_unknown', value: undefined }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: simple, with unknown values', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Number }
|
||||
]
|
||||
const argv = [ 'clive', '--one', '1', 'yeah' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(!result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(result[2].def)
|
||||
a.ok(!result[3].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'unknown_value', arg: 'clive', name: '_unknown', value: undefined },
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' },
|
||||
{ event: 'unknown_value', arg: 'yeah', name: '_unknown', value: undefined }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: simple, with singular defaultOption', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Number },
|
||||
{ name: 'two', defaultOption: true }
|
||||
]
|
||||
const argv = [ 'clive', '--one', '1', 'yeah' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(result[2].def)
|
||||
a.ok(!result[3].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: 'clive', name: 'two', value: 'clive' },
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' },
|
||||
{ event: 'unknown_value', arg: 'yeah', name: '_unknown', value: undefined }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: simple, with multiple defaultOption', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Number },
|
||||
{ name: 'two', defaultOption: true, multiple: true }
|
||||
]
|
||||
const argv = [ 'clive', '--one', '1', 'yeah' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(result[2].def)
|
||||
a.ok(result[3].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: 'clive', name: 'two', value: 'clive' },
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' },
|
||||
{ event: 'set', arg: 'yeah', name: 'two', value: 'yeah' }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: long option, string lazyMultiple bad', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', lazyMultiple: true }
|
||||
]
|
||||
const argv = [ '--one', '1', '2' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(!result[2].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' },
|
||||
{ event: 'unknown_value', arg: '2', name: '_unknown', value: undefined }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: long option, string lazyMultiple good', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', lazyMultiple: true }
|
||||
]
|
||||
const argv = [ '--one', '1', '--one', '2' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(result[2].def)
|
||||
a.ok(result[3].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' },
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '2', name: 'one', value: '2' }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: long option, stopAtFirstUnknown', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one' },
|
||||
{ name: 'two' }
|
||||
]
|
||||
const argv = [ '--one', '1', 'asdf', '--two', '2' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv, stopAtFirstUnknown: true })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(!result[2].def)
|
||||
a.ok(!result[3].def)
|
||||
a.ok(!result[4].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' },
|
||||
{ event: 'unknown_value', arg: 'asdf', name: '_unknown', value: undefined },
|
||||
{ event: 'unknown_value', arg: '--two', name: '_unknown', value: undefined },
|
||||
{ event: 'unknown_value', arg: '2', name: '_unknown', value: undefined }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: long option, stopAtFirstUnknown with defaultOption', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', defaultOption: true },
|
||||
{ name: 'two' }
|
||||
]
|
||||
const argv = [ '1', 'asdf', '--two', '2' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv, stopAtFirstUnknown: true })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(!result[1].def)
|
||||
a.ok(!result[2].def)
|
||||
a.ok(!result[3].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' },
|
||||
{ event: 'unknown_value', arg: 'asdf', name: '_unknown', value: undefined },
|
||||
{ event: 'unknown_value', arg: '--two', name: '_unknown', value: undefined },
|
||||
{ event: 'unknown_value', arg: '2', name: '_unknown', value: undefined }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: long option, stopAtFirstUnknown with defaultOption 2', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', defaultOption: true },
|
||||
{ name: 'two' }
|
||||
]
|
||||
const argv = [ '--one', '1', '--', '--two', '2' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv, stopAtFirstUnknown: true })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(!result[2].def)
|
||||
a.ok(!result[3].def)
|
||||
a.ok(!result[4].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '--one', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' },
|
||||
{ event: 'unknown_value', arg: '--', name: '_unknown', value: undefined },
|
||||
{ event: 'unknown_value', arg: '--two', name: '_unknown', value: undefined },
|
||||
{ event: 'unknown_value', arg: '2', name: '_unknown', value: undefined }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: --option=value', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one' },
|
||||
{ name: 'two' }
|
||||
]
|
||||
const argv = [ '--one=1', '--two=2', '--two=' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(result[2].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '--one=1', name: 'one', value: '1' },
|
||||
{ event: 'set', arg: '--two=2', name: 'two', value: '2' },
|
||||
{ event: 'set', arg: '--two=', name: 'two', value: '' }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: --option=value, unknown option', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one' }
|
||||
]
|
||||
const argv = [ '--three=3' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(!result[0].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'unknown_option', arg: '--three=3', name: '_unknown', value: undefined }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: --option=value where option is boolean', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean }
|
||||
]
|
||||
const argv = [ '--one=1' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'unknown_value', arg: '--one=1', name: '_unknown', value: undefined },
|
||||
{ event: 'set', arg: '--one=1', name: 'one', value: true }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: short option, string', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', alias: 'o' }
|
||||
]
|
||||
const argv = [ '-o', '1' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '-o', name: 'one', value: null },
|
||||
{ event: 'set', arg: '1', name: 'one', value: '1' }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: combined short option, string', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', alias: 'o' },
|
||||
{ name: 'two', alias: 't' }
|
||||
]
|
||||
const argv = [ '-ot', '1' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(result[2].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'set', arg: '-ot', subArg: '-o', name: 'one', value: null },
|
||||
{ event: 'set', arg: '-ot', subArg: '-t', name: 'two', value: null },
|
||||
{ event: 'set', arg: '1', name: 'two', value: '1' }
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('argv-parser: combined short option, one unknown', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', alias: 'o' },
|
||||
{ name: 'two', alias: 't' }
|
||||
]
|
||||
const argv = [ '-xt', '1' ]
|
||||
const parser = new ArgvParser(optionDefinitions, { argv })
|
||||
const result = Array.from(parser)
|
||||
a.ok(!result[0].def)
|
||||
a.ok(result[1].def)
|
||||
a.ok(result[2].def)
|
||||
result.forEach(r => delete r.def)
|
||||
a.deepStrictEqual(result, [
|
||||
{ event: 'unknown_option', arg: '-xt', subArg: '-x', name: '_unknown', value: undefined },
|
||||
{ event: 'set', arg: '-xt', subArg: '-t', name: 'two', value: null },
|
||||
{ event: 'set', arg: '1', name: 'two', value: '1' }
|
||||
])
|
||||
})
|
35
node_modules/command-line-args/test/internals/option-default.js
generated
vendored
Normal file
35
node_modules/command-line-args/test/internals/option-default.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const Option = require('../../lib/option')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('option.set(): defaultValue', function () {
|
||||
const option = new Option({ name: 'two', defaultValue: 'two' })
|
||||
a.strictEqual(option.get(), 'two')
|
||||
option.set('zwei')
|
||||
a.strictEqual(option.get(), 'zwei')
|
||||
})
|
||||
|
||||
runner.test('option.set(): multiple defaultValue', function () {
|
||||
const option = new Option({ name: 'two', multiple: true, defaultValue: [ 'two', 'zwei' ] })
|
||||
a.deepStrictEqual(option.get(), [ 'two', 'zwei' ])
|
||||
option.set('duo')
|
||||
a.deepStrictEqual(option.get(), [ 'duo' ])
|
||||
})
|
||||
|
||||
runner.test('option.set(): falsy defaultValue', function () {
|
||||
const option = new Option({ name: 'one', defaultValue: 0 })
|
||||
a.strictEqual(option.get(), 0)
|
||||
})
|
||||
|
||||
runner.test('option.set(): falsy defaultValue 2', function () {
|
||||
const option = new Option({ name: 'two', defaultValue: false })
|
||||
a.strictEqual(option.get(), false)
|
||||
})
|
||||
|
||||
runner.test('option.set(): falsy defaultValue multiple', function () {
|
||||
const option = new Option({ name: 'one', defaultValue: 0, multiple: true })
|
||||
a.deepStrictEqual(option.get(), [ 0 ])
|
||||
})
|
28
node_modules/command-line-args/test/internals/option-definitions.js
generated
vendored
Normal file
28
node_modules/command-line-args/test/internals/option-definitions.js
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const a = require('assert')
|
||||
const Definitions = require('../../lib/option-definitions')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('.get(long option)', function () {
|
||||
const definitions = Definitions.from([ { name: 'one' } ])
|
||||
a.strictEqual(definitions.get('--one').name, 'one')
|
||||
})
|
||||
|
||||
runner.test('.get(short option)', function () {
|
||||
const definitions = Definitions.from([ { name: 'one', alias: 'o' } ])
|
||||
a.strictEqual(definitions.get('-o').name, 'one')
|
||||
})
|
||||
|
||||
runner.test('.get(name)', function () {
|
||||
const definitions = Definitions.from([ { name: 'one' } ])
|
||||
a.strictEqual(definitions.get('one').name, 'one')
|
||||
})
|
||||
|
||||
runner.test('.validate()', function () {
|
||||
a.throws(function () {
|
||||
const definitions = new Definitions()
|
||||
definitions.load([ { name: 'one' }, { name: 'one' } ])
|
||||
})
|
||||
})
|
55
node_modules/command-line-args/test/internals/option-flag.js
generated
vendored
Normal file
55
node_modules/command-line-args/test/internals/option-flag.js
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const FlagOption = require('../../lib/option-flag')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('type-boolean: single set', function () {
|
||||
const option = new FlagOption({ name: 'one', type: Boolean })
|
||||
|
||||
option.set(undefined)
|
||||
a.strictEqual(option.get(), true)
|
||||
})
|
||||
|
||||
runner.test('type-boolean: single set 2', function () {
|
||||
const option = new FlagOption({ name: 'one', type: Boolean })
|
||||
|
||||
option.set('true')
|
||||
a.strictEqual(option.get(), true)
|
||||
})
|
||||
|
||||
runner.test('type-boolean: set twice', function () {
|
||||
const option = new FlagOption({ name: 'one', type: Boolean })
|
||||
|
||||
option.set(undefined)
|
||||
a.strictEqual(option.get(), true)
|
||||
a.throws(
|
||||
() => option.set('true'),
|
||||
err => err.name === 'ALREADY_SET'
|
||||
)
|
||||
})
|
||||
|
||||
const origBoolean = Boolean
|
||||
|
||||
/* test in contexts which override the standard global Boolean constructor */
|
||||
runner.test('type-boolean: global Boolean overridden', function () {
|
||||
function Boolean () {
|
||||
return origBoolean.apply(origBoolean, arguments)
|
||||
}
|
||||
|
||||
const option = new FlagOption({ name: 'one', type: Boolean })
|
||||
|
||||
option.set()
|
||||
a.strictEqual(option.get(), true)
|
||||
})
|
||||
|
||||
runner.test('type-boolean-multiple: 1', function () {
|
||||
const option = new FlagOption({ name: 'one', type: Boolean, multiple: true })
|
||||
|
||||
option.set(undefined)
|
||||
option.set(undefined)
|
||||
option.set(undefined)
|
||||
|
||||
a.deepStrictEqual(option.get(), [ true, true, true ])
|
||||
})
|
98
node_modules/command-line-args/test/internals/option.js
generated
vendored
Normal file
98
node_modules/command-line-args/test/internals/option.js
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const Option = require('../../lib/option')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('option.set(): simple set string', function () {
|
||||
const option = Option.create({ name: 'two' })
|
||||
a.strictEqual(option.get(), null)
|
||||
a.strictEqual(option.state, 'default')
|
||||
option.set('zwei')
|
||||
a.strictEqual(option.get(), 'zwei')
|
||||
a.strictEqual(option.state, 'set')
|
||||
})
|
||||
|
||||
runner.test('option.set(): simple set boolean', function () {
|
||||
const option = Option.create({ name: 'two', type: Boolean })
|
||||
a.strictEqual(option.get(), null)
|
||||
a.strictEqual(option.state, 'default')
|
||||
option.set()
|
||||
a.strictEqual(option.get(), true)
|
||||
a.strictEqual(option.state, 'set')
|
||||
})
|
||||
|
||||
runner.test('option.set(): simple set string twice', function () {
|
||||
const option = Option.create({ name: 'two' })
|
||||
a.strictEqual(option.get(), null)
|
||||
a.strictEqual(option.state, 'default')
|
||||
option.set('zwei')
|
||||
a.strictEqual(option.get(), 'zwei')
|
||||
a.strictEqual(option.state, 'set')
|
||||
a.throws(
|
||||
() => option.set('drei'),
|
||||
err => err.name === 'ALREADY_SET'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('option.set(): simple set boolean twice', function () {
|
||||
const option = Option.create({ name: 'two', type: Boolean })
|
||||
a.strictEqual(option.get(), null)
|
||||
a.strictEqual(option.state, 'default')
|
||||
option.set()
|
||||
a.strictEqual(option.get(), true)
|
||||
a.strictEqual(option.state, 'set')
|
||||
a.throws(
|
||||
() => option.set(),
|
||||
err => err.name === 'ALREADY_SET'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('option.set(): string multiple', function () {
|
||||
const option = Option.create({ name: 'two', multiple: true })
|
||||
a.deepStrictEqual(option.get(), [])
|
||||
a.strictEqual(option.state, 'default')
|
||||
option.set('1')
|
||||
a.deepStrictEqual(option.get(), [ '1' ])
|
||||
a.strictEqual(option.state, 'set')
|
||||
option.set('2')
|
||||
a.deepStrictEqual(option.get(), [ '1', '2' ])
|
||||
a.strictEqual(option.state, 'set')
|
||||
})
|
||||
|
||||
runner.test('option.set: lazyMultiple', function () {
|
||||
const option = Option.create({ name: 'one', lazyMultiple: true })
|
||||
a.deepStrictEqual(option.get(), [])
|
||||
a.strictEqual(option.state, 'default')
|
||||
option.set('1')
|
||||
a.deepStrictEqual(option.get(), [ '1' ])
|
||||
a.strictEqual(option.state, 'set')
|
||||
option.set('2')
|
||||
a.deepStrictEqual(option.get(), [ '1', '2' ])
|
||||
a.strictEqual(option.state, 'set')
|
||||
})
|
||||
|
||||
runner.test('option.set(): string multiple defaultOption', function () {
|
||||
const option = Option.create({ name: 'two', multiple: true, defaultOption: true })
|
||||
a.deepStrictEqual(option.get(), [])
|
||||
a.strictEqual(option.state, 'default')
|
||||
option.set('1')
|
||||
a.deepStrictEqual(option.get(), [ '1' ])
|
||||
a.strictEqual(option.state, 'set')
|
||||
option.set('2')
|
||||
a.deepStrictEqual(option.get(), [ '1', '2' ])
|
||||
a.strictEqual(option.state, 'set')
|
||||
})
|
||||
|
||||
runner.test('option.set: lazyMultiple defaultOption', function () {
|
||||
const option = Option.create({ name: 'one', lazyMultiple: true, defaultOption: true })
|
||||
a.deepStrictEqual(option.get(), [])
|
||||
a.strictEqual(option.state, 'default')
|
||||
option.set('1')
|
||||
a.deepStrictEqual(option.get(), [ '1' ])
|
||||
a.strictEqual(option.state, 'set')
|
||||
option.set('2')
|
||||
a.deepStrictEqual(option.get(), [ '1', '2' ])
|
||||
a.strictEqual(option.state, 'set')
|
||||
})
|
26
node_modules/command-line-args/test/internals/output.js
generated
vendored
Normal file
26
node_modules/command-line-args/test/internals/output.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const a = require('assert')
|
||||
const Output = require('../../lib/output')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('output.toObject(): no defs set', function () {
|
||||
const output = new Output([
|
||||
{ name: 'one' }
|
||||
])
|
||||
a.deepStrictEqual(output.toObject(), {})
|
||||
})
|
||||
|
||||
runner.test('output.toObject(): one def set', function () {
|
||||
const output = new Output([
|
||||
{ name: 'one' }
|
||||
])
|
||||
const Option = require('../../lib/option')
|
||||
const option = Option.create({ name: 'one' })
|
||||
option.set('yeah')
|
||||
output.set('one', option)
|
||||
a.deepStrictEqual(output.toObject(), {
|
||||
one: 'yeah'
|
||||
})
|
||||
})
|
92
node_modules/command-line-args/test/multiple-lazy.js
generated
vendored
Normal file
92
node_modules/command-line-args/test/multiple-lazy.js
generated
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('lazy multiple: string', function () {
|
||||
const argv = ['--one', 'a', '--one', 'b', '--one', 'd']
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', lazyMultiple: true }
|
||||
]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: ['a', 'b', 'd']
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('lazy multiple: string unset with defaultValue', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', lazyMultiple: true, defaultValue: 1 }
|
||||
]
|
||||
const argv = []
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, { one: [ 1 ] })
|
||||
})
|
||||
|
||||
runner.test('lazy multiple: string, --option=value', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', lazyMultiple: true }
|
||||
]
|
||||
const argv = [ '--one=1', '--one=2' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: [ '1', '2' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('lazy multiple: string, --option=value mix', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', lazyMultiple: true }
|
||||
]
|
||||
const argv = [ '--one=1', '--one=2', '--one', '3' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: [ '1', '2', '3' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('lazy multiple: string, defaultOption', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', lazyMultiple: true, defaultOption: true }
|
||||
]
|
||||
const argv = [ '1', '2' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: [ '1', '2' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('lazy multiple: greedy style, string', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', lazyMultiple: true }
|
||||
]
|
||||
const argv = [ '--one', '1', '2' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'UNKNOWN_VALUE' && err.value === '2'
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('lazy multiple: greedy style, string, --option=value', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', lazyMultiple: true }
|
||||
]
|
||||
const argv = [ '--one=1', '--one=2' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: [ '1', '2' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('lazy multiple: greedy style, string, --option=value mix', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', lazyMultiple: true }
|
||||
]
|
||||
const argv = [ '--one=1', '--one=2', '3' ]
|
||||
a.throws(
|
||||
() => commandLineArgs(optionDefinitions, { argv }),
|
||||
err => err.name === 'UNKNOWN_VALUE' && err.value === '3'
|
||||
)
|
||||
})
|
77
node_modules/command-line-args/test/multiple.js
generated
vendored
Normal file
77
node_modules/command-line-args/test/multiple.js
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('multiple: empty argv', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', multiple: true }
|
||||
]
|
||||
const argv = []
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {})
|
||||
})
|
||||
|
||||
runner.test('multiple: boolean, empty argv', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean, multiple: true }
|
||||
]
|
||||
const argv = []
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, { })
|
||||
})
|
||||
|
||||
runner.test('multiple: string unset with defaultValue', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', multiple: true, defaultValue: 1 }
|
||||
]
|
||||
const argv = []
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, { one: [ 1 ] })
|
||||
})
|
||||
|
||||
runner.test('multiple: string', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', multiple: true }
|
||||
]
|
||||
const argv = [ '--one', '1', '2' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: [ '1', '2' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('multiple: string, --option=value', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', multiple: true }
|
||||
]
|
||||
const argv = [ '--one=1', '--one=2' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: [ '1', '2' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('multiple: string, --option=value mix', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', multiple: true }
|
||||
]
|
||||
const argv = [ '--one=1', '--one=2', '3' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: [ '1', '2', '3' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('multiple: string, defaultOption', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', multiple: true, defaultOption: true }
|
||||
]
|
||||
const argv = [ '1', '2' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: [ '1', '2' ]
|
||||
})
|
||||
})
|
21
node_modules/command-line-args/test/name-alias-mix.js
generated
vendored
Normal file
21
node_modules/command-line-args/test/name-alias-mix.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('name-alias-mix: one of each', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', alias: 'o' },
|
||||
{ name: 'two', alias: 't' },
|
||||
{ name: 'three', alias: 'h' },
|
||||
{ name: 'four', alias: 'f' }
|
||||
]
|
||||
const argv = [ '--one', '-t', '--three' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.strictEqual(result.one, null)
|
||||
a.strictEqual(result.two, null)
|
||||
a.strictEqual(result.three, null)
|
||||
a.strictEqual(result.four, undefined)
|
||||
})
|
19
node_modules/command-line-args/test/name-unicode.js
generated
vendored
Normal file
19
node_modules/command-line-args/test/name-unicode.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('name-unicode: unicode names and aliases are permitted', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'один' },
|
||||
{ name: '两' },
|
||||
{ name: 'три', alias: 'т' }
|
||||
]
|
||||
const argv = [ '--один', '1', '--两', '2', '-т', '3' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.strictEqual(result.один, '1')
|
||||
a.strictEqual(result.两, '2')
|
||||
a.strictEqual(result.три, '3')
|
||||
})
|
54
node_modules/command-line-args/test/notations.js
generated
vendored
Normal file
54
node_modules/command-line-args/test/notations.js
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('getOpt short notation: two flags, one option', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'flagA', alias: 'a' },
|
||||
{ name: 'flagB', alias: 'b' },
|
||||
{ name: 'three', alias: 'c' }
|
||||
]
|
||||
|
||||
const argv = [ '-abc', 'yeah' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
flagA: null,
|
||||
flagB: null,
|
||||
three: 'yeah'
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('option=value notation: two plus a regular notation', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one' },
|
||||
{ name: 'two' },
|
||||
{ name: 'three' }
|
||||
]
|
||||
|
||||
const argv = [ '--one=1', '--two', '2', '--three=3' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.strictEqual(result.one, '1')
|
||||
a.strictEqual(result.two, '2')
|
||||
a.strictEqual(result.three, '3')
|
||||
})
|
||||
|
||||
runner.test('option=value notation: value contains "="', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'url' },
|
||||
{ name: 'two' },
|
||||
{ name: 'three' }
|
||||
]
|
||||
|
||||
let result = commandLineArgs(optionDefinitions, { argv: [ '--url=my-url?q=123', '--two', '2', '--three=3' ] })
|
||||
a.strictEqual(result.url, 'my-url?q=123')
|
||||
a.strictEqual(result.two, '2')
|
||||
a.strictEqual(result.three, '3')
|
||||
|
||||
result = commandLineArgs(optionDefinitions, { argv: [ '--url=my-url?q=123=1' ] })
|
||||
a.strictEqual(result.url, 'my-url?q=123=1')
|
||||
|
||||
result = commandLineArgs({ name: 'my-url' }, { argv: [ '--my-url=my-url?q=123=1' ] })
|
||||
a.strictEqual(result['my-url'], 'my-url?q=123=1')
|
||||
})
|
219
node_modules/command-line-args/test/partial.js
generated
vendored
Normal file
219
node_modules/command-line-args/test/partial.js
generated
vendored
Normal file
@ -0,0 +1,219 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('partial: simple', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', type: Boolean }
|
||||
]
|
||||
const argv = [ '--two', 'two', '--one', 'two' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
one: true,
|
||||
_unknown: [ '--two', 'two', 'two' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: defaultOption', function () {
|
||||
const definitions = [
|
||||
{ name: 'files', type: String, defaultOption: true, multiple: true }
|
||||
]
|
||||
const argv = [ '--files', 'file1', '--one', 'file2' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
files: [ 'file1', 'file2' ],
|
||||
_unknown: [ '--one' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('defaultOption: floating args present but no defaultOption', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', type: Boolean }
|
||||
]
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ 'aaa', '--one', 'aaa', 'aaa' ], partial: true }),
|
||||
{
|
||||
one: true,
|
||||
_unknown: [ 'aaa', 'aaa', 'aaa' ]
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('partial: combined short option, both unknown', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', alias: 'o' },
|
||||
{ name: 'two', alias: 't' }
|
||||
]
|
||||
const argv = [ '-ab' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
_unknown: [ '-a', '-b' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: combined short option, one known, one unknown', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', alias: 'o' },
|
||||
{ name: 'two', alias: 't' }
|
||||
]
|
||||
const argv = [ '-ob' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
one: null,
|
||||
_unknown: [ '-b' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: defaultOption with --option=value and combined short options', function () {
|
||||
const definitions = [
|
||||
{ name: 'files', type: String, defaultOption: true, multiple: true },
|
||||
{ name: 'one', type: Boolean },
|
||||
{ name: 'two', alias: 't', defaultValue: 2 }
|
||||
]
|
||||
const argv = [ 'file1', '--one', 'file2', '-t', '--two=3', 'file3', '-ab' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
files: [ 'file1', 'file2', 'file3' ],
|
||||
two: '3',
|
||||
one: true,
|
||||
_unknown: [ '-a', '-b' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: defaultOption with value equal to defaultValue', function () {
|
||||
const definitions = [
|
||||
{ name: 'file', type: String, defaultOption: true, defaultValue: 'file1' }
|
||||
]
|
||||
const argv = [ 'file1', '--two=3', '--four', '5' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
file: 'file1',
|
||||
_unknown: [ '--two=3', '--four', '5' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: string defaultOption can be set by argv once', function () {
|
||||
const definitions = [
|
||||
{ name: 'file', type: String, defaultOption: true, defaultValue: 'file1' }
|
||||
]
|
||||
const argv = [ '--file', '--file=file2', '--two=3', '--four', '5' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
file: 'file2',
|
||||
_unknown: [ '--two=3', '--four', '5' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: string defaultOption can not be set by argv twice', function () {
|
||||
const definitions = [
|
||||
{ name: 'file', type: String, defaultOption: true, defaultValue: 'file1' }
|
||||
]
|
||||
const argv = [ '--file', '--file=file2', '--two=3', '--four', '5', 'file3' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
file: 'file2',
|
||||
_unknown: [ '--two=3', '--four', '5', 'file3' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: defaultOption with value equal to defaultValue 3', function () {
|
||||
const definitions = [
|
||||
{ name: 'file', type: String, defaultOption: true, defaultValue: 'file1' }
|
||||
]
|
||||
const argv = [ 'file1', 'file2', '--two=3', '--four', '5' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
file: 'file1',
|
||||
_unknown: [ 'file2', '--two=3', '--four', '5' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: multiple', function () {
|
||||
const definitions = [
|
||||
{ name: 'files', type: String, multiple: true }
|
||||
]
|
||||
const argv = [ 'file1', '--files', 'file2', '-t', '--two=3', 'file3', '-ab', '--files=file4' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
files: [ 'file2', 'file4' ],
|
||||
_unknown: [ 'file1', '-t', '--two=3', 'file3', '-a', '-b' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('unknown options: rejected defaultOption values end up in _unknown', function () {
|
||||
const definitions = [
|
||||
{ name: 'foo', type: String },
|
||||
{ name: 'verbose', alias: 'v', type: Boolean },
|
||||
{ name: 'libs', type: String, defaultOption: true }
|
||||
]
|
||||
const argv = [ '--foo', 'bar', '-v', 'libfn', '--libarg', 'val1', '-r' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
foo: 'bar',
|
||||
verbose: true,
|
||||
libs: 'libfn',
|
||||
_unknown: [ '--libarg', 'val1', '-r' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: defaultOption with --option=value notation', function () {
|
||||
const definitions = [
|
||||
{ name: 'files', type: String, multiple: true, defaultOption: true }
|
||||
]
|
||||
const argv = [ 'file1', 'file2', '--unknown=something' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
files: [ 'file1', 'file2' ],
|
||||
_unknown: [ '--unknown=something' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: defaultOption with --option=value notation 2', function () {
|
||||
const definitions = [
|
||||
{ name: 'files', type: String, multiple: true, defaultOption: true }
|
||||
]
|
||||
const argv = [ 'file1', 'file2', '--unknown=something', '--files', 'file3', '--files=file4' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
files: [ 'file1', 'file2', 'file3', 'file4' ],
|
||||
_unknown: [ '--unknown=something' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: defaultOption with --option=value notation 3', function () {
|
||||
const definitions = [
|
||||
{ name: 'files', type: String, multiple: true, defaultOption: true }
|
||||
]
|
||||
const argv = [ '--unknown', 'file1', '--another', 'something', 'file2', '--unknown=something', '--files', 'file3', '--files=file4' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
files: [ 'file1', 'something', 'file2', 'file3', 'file4' ],
|
||||
_unknown: [ '--unknown', '--another', '--unknown=something' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('partial: mulitple unknowns with same name', function () {
|
||||
const definitions = [
|
||||
{ name: 'file' }
|
||||
]
|
||||
const argv = [ '--unknown', '--unknown=something', '--file=file1', '--unknown' ]
|
||||
const options = commandLineArgs(definitions, { argv, partial: true })
|
||||
a.deepStrictEqual(options, {
|
||||
file: 'file1',
|
||||
_unknown: [ '--unknown', '--unknown=something', '--unknown' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('defaultOption: single string', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'files', defaultOption: true }
|
||||
]
|
||||
const argv = [ 'file1', 'file2' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv, partial: true }), {
|
||||
files: 'file1',
|
||||
_unknown: [ 'file2' ]
|
||||
})
|
||||
})
|
45
node_modules/command-line-args/test/stop-at-first-unknown.js
generated
vendored
Normal file
45
node_modules/command-line-args/test/stop-at-first-unknown.js
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const a = require('assert')
|
||||
const commandLineArgs = require('../')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('stopAtFirstUnknown', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean },
|
||||
{ name: 'two', type: Boolean }
|
||||
]
|
||||
const argv = [ '--one', 'a', '--two' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv, stopAtFirstUnknown: true, partial: true })
|
||||
a.deepStrictEqual(result, {
|
||||
one: true,
|
||||
_unknown: [ 'a', '--two' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('stopAtFirstUnknown: with a singlular defaultOption', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', defaultOption: true },
|
||||
{ name: 'two' }
|
||||
]
|
||||
const argv = [ '--one', '1', '--', '--two', '2' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv, stopAtFirstUnknown: true })
|
||||
a.deepStrictEqual(result, {
|
||||
one: '1',
|
||||
_unknown: [ '--', '--two', '2' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('stopAtFirstUnknown: with a singlular defaultOption and partial', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', defaultOption: true },
|
||||
{ name: 'two' }
|
||||
]
|
||||
const argv = [ '--one', '1', '--', '--two', '2' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv, stopAtFirstUnknown: true, partial: true })
|
||||
a.deepStrictEqual(result, {
|
||||
one: '1',
|
||||
_unknown: [ '--', '--two', '2' ]
|
||||
})
|
||||
})
|
46
node_modules/command-line-args/test/type-boolean.js
generated
vendored
Normal file
46
node_modules/command-line-args/test/type-boolean.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('type-boolean: simple', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean }
|
||||
]
|
||||
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--one' ] }),
|
||||
{ one: true }
|
||||
)
|
||||
})
|
||||
|
||||
const origBoolean = Boolean
|
||||
|
||||
/* test in contexts which override the standard global Boolean constructor */
|
||||
runner.test('type-boolean: global Boolean overridden', function () {
|
||||
function Boolean () {
|
||||
return origBoolean.apply(origBoolean, arguments)
|
||||
}
|
||||
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean }
|
||||
]
|
||||
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--one' ] }),
|
||||
{ one: true }
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('type-boolean-multiple: 1', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'array', type: Boolean, multiple: true }
|
||||
]
|
||||
const argv = [ '--array', '--array', '--array' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
array: [ true, true, true ]
|
||||
})
|
||||
})
|
44
node_modules/command-line-args/test/type-none.js
generated
vendored
Normal file
44
node_modules/command-line-args/test/type-none.js
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
const definitions = [
|
||||
{ name: 'one' },
|
||||
{ name: 'two' }
|
||||
]
|
||||
|
||||
runner.test('name: no argv values', function () {
|
||||
const argv = []
|
||||
const result = commandLineArgs(definitions, { argv })
|
||||
a.deepStrictEqual(result, {})
|
||||
})
|
||||
|
||||
runner.test('name: just names, no values', function () {
|
||||
const argv = [ '--one', '--two' ]
|
||||
const result = commandLineArgs(definitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: null,
|
||||
two: null
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('name: just names, one value, one unpassed value', function () {
|
||||
const argv = [ '--one', 'one', '--two' ]
|
||||
const result = commandLineArgs(definitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: 'one',
|
||||
two: null
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('name: just names, two values', function () {
|
||||
const argv = [ '--one', 'one', '--two', 'two' ]
|
||||
const result = commandLineArgs(definitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
one: 'one',
|
||||
two: 'two'
|
||||
})
|
||||
})
|
54
node_modules/command-line-args/test/type-number.js
generated
vendored
Normal file
54
node_modules/command-line-args/test/type-number.js
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('type-number: different values', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Number }
|
||||
]
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--one', '1' ] }),
|
||||
{ one: 1 }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--one' ] }),
|
||||
{ one: null }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--one', '-1' ] }),
|
||||
{ one: -1 }
|
||||
)
|
||||
const result = commandLineArgs(optionDefinitions, { argv: [ '--one', 'asdf' ] })
|
||||
a.ok(isNaN(result.one))
|
||||
})
|
||||
|
||||
runner.test('number multiple: 1', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'array', type: Number, multiple: true }
|
||||
]
|
||||
const argv = [ '--array', '1', '2', '3' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
array: [ 1, 2, 3 ]
|
||||
})
|
||||
a.notDeepStrictEqual(result, {
|
||||
array: [ '1', '2', '3' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('number multiple: 2', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'array', type: Number, multiple: true }
|
||||
]
|
||||
const argv = [ '--array', '1', '--array', '2', '--array', '3' ]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, {
|
||||
array: [ 1, 2, 3 ]
|
||||
})
|
||||
a.notDeepStrictEqual(result, {
|
||||
array: [ '1', '2', '3' ]
|
||||
})
|
||||
})
|
65
node_modules/command-line-args/test/type-other.js
generated
vendored
Normal file
65
node_modules/command-line-args/test/type-other.js
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('type-other: different values', function () {
|
||||
const definitions = [
|
||||
{
|
||||
name: 'file',
|
||||
type: function (file) {
|
||||
return file
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--file', 'one.js' ] }),
|
||||
{ file: 'one.js' }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--file' ] }),
|
||||
{ file: null }
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('type-other: broken custom type function', function () {
|
||||
const definitions = [
|
||||
{
|
||||
name: 'file',
|
||||
type: function (file) {
|
||||
lasdfjsfakn // eslint-disable-line
|
||||
}
|
||||
}
|
||||
]
|
||||
a.throws(function () {
|
||||
commandLineArgs(definitions, { argv: [ '--file', 'one.js' ] })
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('type-other-multiple: different values', function () {
|
||||
const definitions = [
|
||||
{
|
||||
name: 'file',
|
||||
multiple: true,
|
||||
type: function (file) {
|
||||
return file
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--file', 'one.js' ] }),
|
||||
{ file: [ 'one.js' ] }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--file', 'one.js', 'two.js' ] }),
|
||||
{ file: [ 'one.js', 'two.js' ] }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--file' ] }),
|
||||
{ file: [] }
|
||||
)
|
||||
})
|
24
node_modules/command-line-args/test/type-string.js
generated
vendored
Normal file
24
node_modules/command-line-args/test/type-string.js
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('type-string: different values', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: String }
|
||||
]
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--one', 'yeah' ] }),
|
||||
{ one: 'yeah' }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--one' ] }),
|
||||
{ one: null }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--one', '3' ] }),
|
||||
{ one: '3' }
|
||||
)
|
||||
})
|
Reference in New Issue
Block a user