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

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' ] }
*/