change approach again
This commit is contained in:
35
node_modules/command-line-args/test/alias.js
generated
vendored
Normal file
35
node_modules/command-line-args/test/alias.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
const optionDefinitions = [
|
||||
{ name: 'verbose', alias: 'v' },
|
||||
{ name: 'colour', alias: 'c' },
|
||||
{ name: 'number', alias: 'n' },
|
||||
{ name: 'dry-run', alias: 'd' }
|
||||
]
|
||||
|
||||
runner.test('alias: one boolean', function () {
|
||||
const argv = [ '-v' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
verbose: null
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('alias: one --this-type boolean', function () {
|
||||
const argv = [ '-d' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
'dry-run': null
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('alias: one boolean, one string', function () {
|
||||
const argv = [ '-v', '-c' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
verbose: null,
|
||||
colour: null
|
||||
})
|
||||
})
|
24
node_modules/command-line-args/test/ambiguous-input.js
generated
vendored
Normal file
24
node_modules/command-line-args/test/ambiguous-input.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('ambiguous input: value looks like option', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colour', type: String, alias: 'c' }
|
||||
]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv: [ '-c', 'red' ] }), {
|
||||
colour: 'red'
|
||||
})
|
||||
a.throws(function () {
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--colour', '--red' ] })
|
||||
})
|
||||
a.doesNotThrow(function () {
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--colour=--red' ] })
|
||||
})
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv: [ '--colour=--red' ] }), {
|
||||
colour: '--red'
|
||||
})
|
||||
})
|
57
node_modules/command-line-args/test/bad-input.js
generated
vendored
Normal file
57
node_modules/command-line-args/test/bad-input.js
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('bad-input: handles missing option value', function () {
|
||||
const definitions = [
|
||||
{ name: 'colour', type: String },
|
||||
{ name: 'files' }
|
||||
]
|
||||
a.deepStrictEqual(commandLineArgs(definitions, { argv: [ '--colour' ] }), {
|
||||
colour: null
|
||||
})
|
||||
a.deepStrictEqual(commandLineArgs(definitions, { argv: [ '--colour', '--files', 'yeah' ] }), {
|
||||
colour: null,
|
||||
files: 'yeah'
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('bad-input: handles arrays with relative paths', function () {
|
||||
const definitions = [
|
||||
{ name: 'colours', type: String, multiple: true }
|
||||
]
|
||||
const argv = [ '--colours', '../what', '../ever' ]
|
||||
a.deepStrictEqual(commandLineArgs(definitions, { argv }), {
|
||||
colours: [ '../what', '../ever' ]
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('bad-input: empty string', function () {
|
||||
const definitions = [
|
||||
{ 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.deepStrictEqual(commandLineArgs(definitions, { argv }), {
|
||||
one: '',
|
||||
two: 0,
|
||||
three: [ 0, 0 ],
|
||||
four: '',
|
||||
five: true
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('bad-input: non-strings in argv', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', type: Number }
|
||||
]
|
||||
const argv = [ '--one', 1 ]
|
||||
const result = commandLineArgs(definitions, { argv })
|
||||
a.deepStrictEqual(result, { one: 1 })
|
||||
})
|
72
node_modules/command-line-args/test/class-argv.js
generated
vendored
Normal file
72
node_modules/command-line-args/test/class-argv.js
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const a = require('assert')
|
||||
const Argv = require('../lib/argv')
|
||||
const Definitions = require('../lib/definitions')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('.expandOptionEqualsNotation()', function () {
|
||||
const argv = new Argv()
|
||||
argv.load([ '--one=1', '--two', '2', '--three=3', '4' ])
|
||||
argv.expandOptionEqualsNotation()
|
||||
a.deepEqual(argv, [
|
||||
'--one', '552f3a31-14cd-4ced-bd67-656a659e9efb1', '--two', '2', '--three', '552f3a31-14cd-4ced-bd67-656a659e9efb3', '4'
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('.expandGetoptNotation()', function () {
|
||||
const argv = new Argv()
|
||||
argv.load([ '-abc' ])
|
||||
argv.expandGetoptNotation()
|
||||
a.deepEqual(argv.slice(), [
|
||||
'-a', '-b', '-c'
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('.expandGetoptNotation() with values', function () {
|
||||
const argv = new Argv()
|
||||
argv.load([ '-abc', '1', '-a', '2', '-bc' ])
|
||||
argv.expandGetoptNotation()
|
||||
a.deepEqual(argv, [
|
||||
'-a', '-b', '-c', '1', '-a', '2', '-b', '-c'
|
||||
])
|
||||
})
|
||||
|
||||
runner.test('.validate()', function () {
|
||||
const definitions = new Definitions()
|
||||
definitions.load([
|
||||
{ name: 'one', type: Number }
|
||||
])
|
||||
|
||||
a.doesNotThrow(function () {
|
||||
const argv = new Argv()
|
||||
argv.load([ '--one', '1' ])
|
||||
argv.validate(definitions)
|
||||
})
|
||||
|
||||
a.throws(function () {
|
||||
const argv = new Argv()
|
||||
argv.load([ '--one', '--two' ])
|
||||
argv.validate(definitions)
|
||||
})
|
||||
|
||||
a.throws(function () {
|
||||
const argv = new Argv()
|
||||
argv.load([ '--one', '2', '--two', 'two' ])
|
||||
argv.validate(definitions)
|
||||
})
|
||||
|
||||
a.throws(function () {
|
||||
const argv = new Argv()
|
||||
argv.load([ '-a', '2' ])
|
||||
argv.validate(definitions)
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('expandOptionEqualsNotation', function () {
|
||||
const argv = new Argv()
|
||||
argv.load([ '--one=tree' ])
|
||||
argv.expandOptionEqualsNotation()
|
||||
a.deepEqual(argv, [ '--one', '552f3a31-14cd-4ced-bd67-656a659e9efbtree' ])
|
||||
})
|
19
node_modules/command-line-args/test/class-definitions.js
generated
vendored
Normal file
19
node_modules/command-line-args/test/class-definitions.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const a = require('assert')
|
||||
const Definitions = require('../lib/definitions')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('.get()', function () {
|
||||
const definitions = new Definitions()
|
||||
definitions.load([ { name: 'one', defaultValue: 'eins' } ])
|
||||
a.strictEqual(definitions.get('--one').name, 'one')
|
||||
})
|
||||
|
||||
runner.test('.validate()', function () {
|
||||
a.throws(function () {
|
||||
const definitions = new Definitions()
|
||||
definitions.load([ { name: 'one' }, { name: 'one' } ])
|
||||
})
|
||||
})
|
98
node_modules/command-line-args/test/class-output.js
generated
vendored
Normal file
98
node_modules/command-line-args/test/class-output.js
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const a = require('assert')
|
||||
const Output = require('../lib/output')
|
||||
const Definitions = require('../lib/definitions')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('output.setFlag(name): initial value', function () {
|
||||
let definitions = new Definitions()
|
||||
definitions.load([
|
||||
{ name: 'one', type: Number }
|
||||
])
|
||||
let output = new Output(definitions)
|
||||
a.strictEqual(output.get('one'), undefined)
|
||||
output.setFlag('--one')
|
||||
a.strictEqual(output.get('one'), null)
|
||||
|
||||
definitions.load([
|
||||
{ name: 'one', type: Boolean }
|
||||
])
|
||||
output = new Output(definitions)
|
||||
a.strictEqual(output.get('one'), undefined)
|
||||
output.setFlag('--one')
|
||||
a.strictEqual(output.get('one'), true)
|
||||
})
|
||||
|
||||
runner.test('output.setOptionValue(name, value)', function () {
|
||||
const definitions = new Definitions()
|
||||
definitions.load([
|
||||
{ name: 'one', type: Number, defaultValue: 1 }
|
||||
])
|
||||
const output = new Output(definitions)
|
||||
a.strictEqual(output.get('one'), 1)
|
||||
output.setOptionValue('--one', '2')
|
||||
a.strictEqual(output.get('one'), 2)
|
||||
})
|
||||
|
||||
runner.test('output.setOptionValue(name, value): multiple, defaultValue', function () {
|
||||
const definitions = new Definitions()
|
||||
definitions.load([
|
||||
{ name: 'one', type: Number, multiple: true, defaultValue: [ 1 ] }
|
||||
])
|
||||
const output = new Output(definitions)
|
||||
a.deepStrictEqual(output.get('one'), [ 1 ])
|
||||
output.setOptionValue('--one', '2')
|
||||
a.deepStrictEqual(output.get('one'), [ 2 ])
|
||||
})
|
||||
|
||||
runner.test('output.setOptionValue(name, value): multiple 2', function () {
|
||||
const definitions = new Definitions()
|
||||
definitions.load([
|
||||
{ name: 'one', type: Number, multiple: true }
|
||||
])
|
||||
const output = new Output(definitions)
|
||||
a.deepStrictEqual(output.get('one'), undefined)
|
||||
output.setOptionValue('--one', '2')
|
||||
a.deepStrictEqual(output.get('one'), [ 2 ])
|
||||
output.setOptionValue('--one', '3')
|
||||
a.deepStrictEqual(output.get('one'), [ 2, 3 ])
|
||||
})
|
||||
|
||||
runner.test('output.setValue(value): no defaultOption', function () {
|
||||
const definitions = new Definitions()
|
||||
definitions.load([
|
||||
{ name: 'one', type: Number }
|
||||
])
|
||||
const output = new Output(definitions)
|
||||
a.deepStrictEqual(output.get('one'), undefined)
|
||||
output.setValue('2')
|
||||
a.deepStrictEqual(output.get('one'), undefined)
|
||||
a.deepStrictEqual(output.unknown, [ '2' ])
|
||||
})
|
||||
|
||||
runner.test('output.setValue(value): with defaultOption', function () {
|
||||
const definitions = new Definitions()
|
||||
definitions.load([
|
||||
{ name: 'one', type: Number, defaultOption: true }
|
||||
])
|
||||
const output = new Output(definitions)
|
||||
a.deepStrictEqual(output.get('one'), undefined)
|
||||
output.setValue('2')
|
||||
a.deepStrictEqual(output.get('one'), 2)
|
||||
a.deepStrictEqual(output.unknown, [])
|
||||
})
|
||||
|
||||
runner.test('output.setValue(value): multiple', function () {
|
||||
const definitions = new Definitions()
|
||||
definitions.load([
|
||||
{ name: 'one', multiple: true, defaultOption: true }
|
||||
])
|
||||
const output = new Output(definitions)
|
||||
a.deepStrictEqual(output.get('one'), undefined)
|
||||
output.setValue('1')
|
||||
a.deepStrictEqual(output.get('one'), [ '1' ])
|
||||
output.setValue('2')
|
||||
a.deepStrictEqual(output.get('one'), [ '1', '2' ])
|
||||
})
|
99
node_modules/command-line-args/test/default-option.js
generated
vendored
Normal file
99
node_modules/command-line-args/test/default-option.js
generated
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('defaultOption: string', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'files', defaultOption: true }
|
||||
]
|
||||
const argv = [ 'file1', 'file2' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
files: 'file1'
|
||||
})
|
||||
})
|
||||
|
||||
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 between other arg/value pairs', 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 between other arg/value pairs 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' ]
|
||||
})
|
||||
})
|
||||
|
||||
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' ] }),
|
||||
{ one: true }
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('defaultOption: non-multiple should take first value', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'file', defaultOption: true }
|
||||
]
|
||||
const argv = [ 'file1', 'file2' ]
|
||||
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
file: 'file1'
|
||||
})
|
||||
})
|
||||
|
||||
runner.test('defaultOption: non-multiple 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.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
|
||||
file: 'file1',
|
||||
two: true,
|
||||
one: true
|
||||
})
|
||||
})
|
145
node_modules/command-line-args/test/default-value.js
generated
vendored
Normal file
145
node_modules/command-line-args/test/default-value.js
generated
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('default value', function () {
|
||||
let defs = [
|
||||
{ name: 'one' },
|
||||
{ name: 'two', defaultValue: 'two' }
|
||||
]
|
||||
let argv = [ '--one', '1' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
|
||||
one: '1',
|
||||
two: 'two'
|
||||
})
|
||||
|
||||
defs = [ { name: 'two', defaultValue: 'two' } ]
|
||||
argv = []
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: 'two' })
|
||||
|
||||
defs = [ { name: 'two', defaultValue: 'two' } ]
|
||||
argv = [ '--two', 'zwei' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: 'zwei' })
|
||||
|
||||
defs = [ { name: 'two', multiple: true, defaultValue: [ 'two', 'zwei' ] } ]
|
||||
argv = [ '--two', 'duo' ]
|
||||
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: [ 'duo' ] })
|
||||
})
|
||||
|
||||
runner.test('default value 2', function () {
|
||||
const defs = [{ name: 'two', multiple: true, defaultValue: ['two', 'zwei'] }]
|
||||
const result = commandLineArgs(defs, [])
|
||||
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: [ './' ]
|
||||
})
|
||||
})
|
21
node_modules/command-line-args/test/detect-process-argv.js
generated
vendored
Normal file
21
node_modules/command-line-args/test/detect-process-argv.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('detect process.argv: should automatically remove first two argv items', 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' ])
|
||||
})
|
176
node_modules/command-line-args/test/exceptions.js
generated
vendored
Normal file
176
node_modules/command-line-args/test/exceptions.js
generated
vendored
Normal file
@ -0,0 +1,176 @@
|
||||
'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' ]
|
||||
try {
|
||||
commandLineArgs(optionDefinitions, { argv })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'NAME_MISSING')
|
||||
}
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: throws if dev set a numeric alias', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colours', alias: '1' }
|
||||
]
|
||||
const argv = [ '--colours', 'red' ]
|
||||
|
||||
try {
|
||||
commandLineArgs(optionDefinitions, { argv })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'INVALID_ALIAS')
|
||||
}
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: throws if dev set an alias of "-"', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colours', alias: '-' }
|
||||
]
|
||||
const argv = [ '--colours', 'red' ]
|
||||
|
||||
try {
|
||||
commandLineArgs(optionDefinitions, { argv })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'INVALID_ALIAS')
|
||||
}
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: multi-character alias', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', alias: 'aa' }
|
||||
]
|
||||
const argv = [ '--one', 'red' ]
|
||||
|
||||
try {
|
||||
commandLineArgs(optionDefinitions, { argv })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'INVALID_ALIAS')
|
||||
}
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: invalid type values', function () {
|
||||
const argv = [ '--one', 'something' ]
|
||||
try {
|
||||
commandLineArgs([ { name: 'one', type: 'string' } ], { argv })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'INVALID_TYPE')
|
||||
}
|
||||
|
||||
try {
|
||||
commandLineArgs([ { name: 'one', type: 234 } ], { argv })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'INVALID_TYPE')
|
||||
}
|
||||
|
||||
try {
|
||||
commandLineArgs([ { name: 'one', type: {} } ], { argv })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'INVALID_TYPE')
|
||||
}
|
||||
|
||||
a.doesNotThrow(function () {
|
||||
commandLineArgs([ { name: 'one', type: function () {} } ], { argv })
|
||||
}, /invalid/i)
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: value without option definition', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Number }
|
||||
]
|
||||
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--one', '1' ] }),
|
||||
{ one: 1 }
|
||||
)
|
||||
|
||||
try {
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--one', '--two' ] })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'UNKNOWN_OPTION')
|
||||
}
|
||||
|
||||
try {
|
||||
commandLineArgs(optionDefinitions, { argv: [ '--one', '2', '--two', 'two' ] })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'UNKNOWN_OPTION')
|
||||
}
|
||||
|
||||
try {
|
||||
commandLineArgs(optionDefinitions, { argv: [ '-a', '2' ] })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'UNKNOWN_OPTION')
|
||||
}
|
||||
|
||||
try {
|
||||
commandLineArgs(optionDefinitions, { argv: [ '-sdf' ] })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'UNKNOWN_OPTION', 'getOpts')
|
||||
}
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: duplicate name', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'colours' },
|
||||
{ name: 'colours' }
|
||||
]
|
||||
const argv = [ '--colours', 'red' ]
|
||||
|
||||
try {
|
||||
commandLineArgs(optionDefinitions, { argv })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'DUPLICATE_NAME')
|
||||
}
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: duplicate alias', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', alias: 'a' },
|
||||
{ name: 'two', alias: 'a' }
|
||||
]
|
||||
const argv = [ '--one', 'red' ]
|
||||
|
||||
try {
|
||||
commandLineArgs(optionDefinitions, { argv })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'DUPLICATE_ALIAS')
|
||||
}
|
||||
})
|
||||
|
||||
runner.test('err-invalid-definition: multiple defaultOption', function () {
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', defaultOption: true },
|
||||
{ name: 'two', defaultOption: true }
|
||||
]
|
||||
const argv = [ '--one', 'red' ]
|
||||
|
||||
try {
|
||||
commandLineArgs(optionDefinitions, { argv })
|
||||
a.fail()
|
||||
} catch (err) {
|
||||
a.strictEqual(err.name, 'DUPLICATE_DEFAULT_OPTION')
|
||||
}
|
||||
})
|
||||
|
||||
runner.test('err-invalid-defaultOption: defaultOption on a Boolean type')
|
120
node_modules/command-line-args/test/grouping.js
generated
vendored
Normal file
120
node_modules/command-line-args/test/grouping.js
generated
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
'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' }
|
||||
})
|
||||
})
|
33
node_modules/command-line-args/test/multiple.js
generated
vendored
Normal file
33
node_modules/command-line-args/test/multiple.js
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('multiple: string unset', function () {
|
||||
const argv = []
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', multiple: true }
|
||||
]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, { })
|
||||
})
|
||||
|
||||
runner.test('multiple: string unset with defaultValue', function () {
|
||||
const argv = []
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', multiple: true, defaultValue: 1 }
|
||||
]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, { one: [ 1 ]})
|
||||
})
|
||||
|
||||
runner.test('multiple: boolean unset', function () {
|
||||
const argv = []
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', type: Boolean, multiple: true }
|
||||
]
|
||||
const result = commandLineArgs(optionDefinitions, { argv })
|
||||
a.deepStrictEqual(result, { })
|
||||
})
|
22
node_modules/command-line-args/test/name-alias-mix.js
generated
vendored
Normal file
22
node_modules/command-line-args/test/name-alias-mix.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
const optionDefinitions = [
|
||||
{ name: 'one', alias: 'o' },
|
||||
{ name: 'two', alias: 't' },
|
||||
{ name: 'three', alias: 'h' },
|
||||
{ name: 'four', alias: 'f' }
|
||||
]
|
||||
|
||||
runner.test('name-alias-mix: one of each', function () {
|
||||
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)
|
||||
})
|
20
node_modules/command-line-args/test/name-unicode.js
generated
vendored
Normal file
20
node_modules/command-line-args/test/name-unicode.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
const optionDefinitions = [
|
||||
{ name: 'один' },
|
||||
{ name: '两' },
|
||||
{ name: 'три', alias: 'т' }
|
||||
]
|
||||
|
||||
runner.test('name-unicode: unicode names and aliases are permitted', function () {
|
||||
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')
|
||||
})
|
11
node_modules/command-line-args/test/option.js
generated
vendored
Normal file
11
node_modules/command-line-args/test/option.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const a = require('assert')
|
||||
const option = require('../lib/option')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('option', function () {
|
||||
a.strictEqual(option.isOption('--yeah'), true)
|
||||
a.strictEqual(option.isOption('в--yeah'), false)
|
||||
})
|
200
node_modules/command-line-args/test/partial.js
generated
vendored
Normal file
200
node_modules/command-line-args/test/partial.js
generated
vendored
Normal file
@ -0,0 +1,200 @@
|
||||
'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('partial: defaultOption 2', 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: defaultOption with value equal to defaultValue 2', function () {
|
||||
const definitions = [
|
||||
{ name: 'file', type: String, defaultOption: true, defaultValue: 'file1' }
|
||||
]
|
||||
const argv = [ '--file', '--file=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: 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: groups', 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: 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' ]
|
||||
})
|
||||
})
|
||||
|
||||
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' ]
|
||||
})
|
||||
})
|
70
node_modules/command-line-args/test/type-boolean.js
generated
vendored
Normal file
70
node_modules/command-line-args/test/type-boolean.js
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('type-boolean: different values', function () {
|
||||
const definitions = [
|
||||
{ name: 'one', type: Boolean }
|
||||
]
|
||||
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one' ] }),
|
||||
{ one: true }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one', 'true' ] }),
|
||||
{ one: true }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one', 'false' ] }),
|
||||
{ one: true }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one', 'sfsgf' ] }),
|
||||
{ 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 definitions = [
|
||||
{ name: 'one', type: Boolean }
|
||||
]
|
||||
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one', 'true' ] }),
|
||||
{ one: true }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one', 'false' ] }),
|
||||
{ one: true }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one', 'sfsgf' ] }),
|
||||
{ one: true }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one' ] }),
|
||||
{ one: true }
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('type-boolean-multiple: 1', function () {
|
||||
const definitions = [
|
||||
{ name: 'array', type: Boolean, multiple: true }
|
||||
]
|
||||
const argv = [ '--array', '--array', '--array' ]
|
||||
const result = commandLineArgs(definitions, { 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: [] }
|
||||
)
|
||||
})
|
25
node_modules/command-line-args/test/type-string.js
generated
vendored
Normal file
25
node_modules/command-line-args/test/type-string.js
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const commandLineArgs = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const definitions = [
|
||||
{ name: 'one', type: String }
|
||||
]
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
runner.test('type-string: different values', function () {
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one', 'yeah' ] }),
|
||||
{ one: 'yeah' }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one' ] }),
|
||||
{ one: null }
|
||||
)
|
||||
a.deepStrictEqual(
|
||||
commandLineArgs(definitions, { argv: [ '--one', '3' ] }),
|
||||
{ one: '3' }
|
||||
)
|
||||
})
|
Reference in New Issue
Block a user