change approach again

This commit is contained in:
2018-05-09 14:31:22 +02:00
parent 54a933c83a
commit 0686e02b75
2252 changed files with 864743 additions and 270 deletions

33
node_modules/command-line-args/example/mocha.js generated vendored Normal file
View File

@ -0,0 +1,33 @@
'use strict'
/* demonstrates use in a mocha test script */
const assert = require('assert')
const commandLineArgs = require('../')
/*
enable partial parsing to prevent `UNKNOWN_OPTION` exceptions being thrown
if the user sets mocha-specific options (e.g. --no-colors)
*/
const options = commandLineArgs({ name: 'value', type: Number }, { partial: true })
describe('Array', function () {
describe('#indexOf()', function () {
it('should pass when the supplied value is between 1 and 3', function () {
assert.ok([ 1, 2, 3 ].indexOf(options.value) > -1)
})
})
})
/*
Example output:
$ mocha example/mocha.js --value 3 --no-colors
Array
#indexOf()
✓ should pass when the supplied value is between 1 and 3
1 passing (7ms)
*/

35
node_modules/command-line-args/example/type.js generated vendored Normal file
View File

@ -0,0 +1,35 @@
'use strict'
const commandLineArgs = require('../')
/* demonstrates a custom `type` function which returns a class instance */
class FileDetails {
constructor (filename) {
const fs = require('fs')
this.filename = filename
this.exists = fs.existsSync(filename)
}
}
const optionDefinitions = [
{
name: 'file',
multiple: true,
defaultOption: true,
type: filename => new FileDetails(filename)
},
{ name: 'depth', type: Number }
]
const options = commandLineArgs(optionDefinitions)
console.log(options)
/*
Example output:
$ node example/type.js package.json nothing.js
{ file:
[ FileDetails { filename: 'package.json', exists: true },
FileDetails { filename: 'nothing.js', exists: false } ] }
*/

76
node_modules/command-line-args/example/typical.js generated vendored Normal file
View File

@ -0,0 +1,76 @@
'use strict'
const commandLineArgs = require('../')
const commandLineUsage = require('command-line-usage')
/*
This example shows typical use alongside command-line-usage
https://github.com/75lb/command-line-usage
*/
const optionDefinitions = [
{
name: 'help',
alias: 'h',
type: Boolean,
description: 'Display this usage guide.'
},
{
name: 'src',
type: String,
multiple: true,
defaultOption: true,
description: 'The input files to process',
typeLabel: '<files>' },
{
name: 'timeout',
alias: 't',
type: Number,
description: 'Timeout value in ms',
typeLabel: '<ms>' },
{
name: 'log',
alias: 'l',
type: Boolean,
description: 'info, warn or error'
}
]
const options = commandLineArgs(optionDefinitions)
if (options.help) {
const usage = commandLineUsage([
{
header: 'Typical Example',
content: 'A simple example demonstrating typical usage.'
},
{
header: 'Options',
optionList: optionDefinitions
},
{
content: 'Project home: [underline]{https://github.com/me/example}'
}
])
console.log(usage)
}
/*
Example output:
$ node example/typical.js --help
Typical Example
A simple example demonstrating typical usage.
Options
-h, --help Display this usage guide.
--src <files> The input files to process
-t, --timeout <ms> Timeout value in ms
-l, --log info, warn or error
Project home: https://github.com/me/example
*/

22
node_modules/command-line-args/example/unknown.js generated vendored Normal file
View File

@ -0,0 +1,22 @@
'use strict'
const commandLineArgs = require('../')
const optionDefinitions = [
{ name: 'depth', type: Number },
{ name: 'files', alias: 'f', type: String, multiple: true, defaultOption: true }
]
const options = commandLineArgs(optionDefinitions, { partial: true })
console.log(options)
/*
Example output:
$ node example/unknown.js --depth 3 package.json README.md --unknown1 --unknown2
{ depth: 3,
files: [ 'package.json', 'README.md' ],
_unknown: [ '--unknown1', '--unknown2' ] }
*/

37
node_modules/command-line-args/example/validate.js generated vendored Normal file
View File

@ -0,0 +1,37 @@
/*
command-line-args parses the command line but does not validate what was collected.
This example demonstrates how the values collected can be validated.
*/
'use strict'
const commandLineArgs = require('../')
const fs = require('fs')
const optionDefinitions = [
{ name: 'help', alias: 'h', type: Boolean },
{ name: 'files', type: String, multiple: true, defaultOption: true },
{ name: 'log-level', type: String }
]
const options = commandLineArgs(optionDefinitions)
const valid =
options.help ||
(
/* all supplied files should exist and --log-level should be one from the list */
options.files &&
options.files.length &&
options.files.every(fs.existsSync) &&
[ 'info', 'warn', 'error', undefined ].includes(options['log-level'])
)
console.log('Your options are', valid ? 'valid' : 'invalid')
console.log(options)
/*
Example output:
$ node example/validate.js package.json README.md
Your options are valid
{ files: [ 'package.json', 'README.md' ] }
*/