This commit is contained in:
2018-05-16 10:10:23 +02:00
commit 79abc63edd
597 changed files with 93351 additions and 0 deletions

8
node_modules/command-line-args/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,8 @@
language: node_js
node_js:
- 9
- 8
- 7
- 6
- 5
- 4

21
node_modules/command-line-args/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014-18 Lloyd Brookes <75pound@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

103
node_modules/command-line-args/README.md generated vendored Normal file
View File

@ -0,0 +1,103 @@
[![view on npm](https://img.shields.io/npm/v/command-line-args.svg)](https://www.npmjs.org/package/command-line-args)
[![npm module downloads](https://img.shields.io/npm/dt/command-line-args.svg)](https://www.npmjs.org/package/command-line-args)
[![Build Status](https://travis-ci.org/75lb/command-line-args.svg?branch=master)](https://travis-ci.org/75lb/command-line-args)
[![Coverage Status](https://coveralls.io/repos/github/75lb/command-line-args/badge.svg?branch=master)](https://coveralls.io/github/75lb/command-line-args?branch=master)
[![Dependency Status](https://david-dm.org/75lb/command-line-args.svg)](https://david-dm.org/75lb/command-line-args)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)
[![Join the chat at https://gitter.im/75lb/command-line-args](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/75lb/command-line-args?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
***Upgraders, please read the [release notes](https://github.com/75lb/command-line-args/releases)***
# command-line-args
A mature, feature-complete library to parse command-line options.
## Synopsis
You can set options using the main notation standards ([learn more](https://github.com/75lb/command-line-args/wiki/Notation-rules)). These commands are all equivalent, setting the same values:
```
$ example --verbose --timeout=1000 --src one.js --src two.js
$ example --verbose --timeout 1000 --src one.js two.js
$ example -vt 1000 --src one.js two.js
$ example -vt 1000 one.js two.js
```
To access the values, first create a list of [option definitions](https://github.com/75lb/command-line-args/blob/master/doc/option-definition.md) describing the options your application accepts. The [`type`](https://github.com/75lb/command-line-args/blob/master/doc/option-definition.md#optiontype--function) property is a setter function (the value supplied is passed through this), giving you full control over the value received.
```js
const optionDefinitions = [
{ name: 'verbose', alias: 'v', type: Boolean },
{ name: 'src', type: String, multiple: true, defaultOption: true },
{ name: 'timeout', alias: 't', type: Number }
]
```
Next, parse the options using [commandLineArgs()](https://github.com/75lb/command-line-args/blob/master/doc/API.md#commandlineargsoptiondefinitions-options--object-):
```js
const commandLineArgs = require('command-line-args')
const options = commandLineArgs(optionDefinitions)
```
`options` now looks like this:
```js
{
src: [
'one.js',
'two.js'
],
verbose: true,
timeout: 1000
}
```
### Advanced usage
Beside the above typical usage, you can configure command-line-args to accept more advanced syntax forms.
* [Command-based syntax](https://github.com/75lb/command-line-args/wiki/Implement-command-parsing-(git-style)) (git style) in the form:
```
$ executable <command> [options]
```
For example.
```
$ git commit --squash -m "This is my commit message"
```
* [Command and sub-command syntax](https://github.com/75lb/command-line-args/wiki/Implement-multiple-command-parsing-(docker-style)) (docker style) in the form:
```
$ executable <command> [options] <sub-command> [options]
```
For example.
```
$ docker run --detached --image centos bash -c yum install -y httpd
```
## Usage guide generation
A usage guide (typically printed when `--help` is set) can be generated using [command-line-usage](https://github.com/75lb/command-line-usage). See the examples below and [read the documentation](https://github.com/75lb/command-line-usage) for instructions how to create them.
A typical usage guide example.
![usage](https://raw.githubusercontent.com/75lb/command-line-usage/master/example/screens/footer.png)
The [polymer-cli](https://github.com/Polymer/polymer-cli/) usage guide is a good real-life example.
![usage](https://raw.githubusercontent.com/75lb/command-line-usage/master/example/screens/polymer.png)
## Further Reading
There is plenty more to learn, please see [the wiki](https://github.com/75lb/command-line-args/wiki) for examples and documentation.
## Install
```sh
$ npm install command-line-args --save
```
* * *
&copy; 2014-18 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown).

35
node_modules/command-line-args/doc/API.md generated vendored Normal file
View File

@ -0,0 +1,35 @@
<a name="module_command-line-args"></a>
## command-line-args
<a name="exp_module_command-line-args--commandLineArgs"></a>
### commandLineArgs(optionDefinitions, [options]) ⇒ <code>object</code> ⏏
Returns an object containing all option values set on the command line. By default it parses the global [`process.argv`](https://nodejs.org/api/process.html#process_process_argv) array.
Parsing is strict by default - an exception is thrown if the user sets a singular option more than once or sets an unknown value or option (one without a valid [definition](https://github.com/75lb/command-line-args/blob/master/doc/option-definition.md)). To be more permissive, enabling [partial](https://github.com/75lb/command-line-args/wiki/Partial-mode-example) or [stopAtFirstUnknown](https://github.com/75lb/command-line-args/wiki/stopAtFirstUnknown) modes will return known options in the usual manner while collecting unknown arguments in a separate `_unknown` property.
**Kind**: Exported function
**Throws**:
- `UNKNOWN_OPTION` If `options.partial` is false and the user set an undefined option. The `err.optionName` property contains the arg that specified an unknown option, e.g. `--one`.
- `UNKNOWN_VALUE` If `options.partial` is false and the user set a value unaccounted for by an option definition. The `err.value` property contains the unknown value, e.g. `5`.
- `ALREADY_SET` If a user sets a singular, non-multiple option more than once. The `err.optionName` property contains the option name that has already been set, e.g. `one`.
- `INVALID_DEFINITIONS`
- If an option definition is missing the required `name` property
- If an option definition has a `type` value that's not a function
- If an alias is numeric, a hyphen or a length other than 1
- If an option definition name was used more than once
- If an option definition alias was used more than once
- If more than one option definition has `defaultOption: true`
- If a `Boolean` option is also set as the `defaultOption`.
| Param | Type | Description |
| --- | --- | --- |
| optionDefinitions | <code>Array.&lt;module:definition&gt;</code> | An array of [OptionDefinition](https://github.com/75lb/command-line-args/blob/master/doc/option-definition.md) objects |
| [options] | <code>object</code> | Options. |
| [options.argv] | <code>Array.&lt;string&gt;</code> | An array of strings which, if present will be parsed instead of `process.argv`. |
| [options.partial] | <code>boolean</code> | If `true`, an array of unknown arguments is returned in the `_unknown` property of the output. |
| [options.stopAtFirstUnknown] | <code>boolean</code> | If `true`, parsing will stop at the first unknown argument and the remaining arguments returned in `_unknown`. When set, `partial: true` is also implied. |
| [options.camelCase] | <code>boolean</code> | If `true`, options with hypenated names (e.g. `move-to`) will be returned in camel-case (e.g. `moveTo`). |

244
node_modules/command-line-args/doc/option-definition.md generated vendored Normal file
View File

@ -0,0 +1,244 @@
<a name="module_option-definition"></a>
## option-definition
* [option-definition](#module_option-definition)
* [OptionDefinition](#exp_module_option-definition--OptionDefinition) ⏏
* [.name](#module_option-definition--OptionDefinition+name) : <code>string</code>
* [.type](#module_option-definition--OptionDefinition+type) : <code>function</code>
* [.alias](#module_option-definition--OptionDefinition+alias) : <code>string</code>
* [.multiple](#module_option-definition--OptionDefinition+multiple) : <code>boolean</code>
* [.lazyMultiple](#module_option-definition--OptionDefinition+lazyMultiple) : <code>boolean</code>
* [.defaultOption](#module_option-definition--OptionDefinition+defaultOption) : <code>boolean</code>
* [.defaultValue](#module_option-definition--OptionDefinition+defaultValue) : <code>\*</code>
* [.group](#module_option-definition--OptionDefinition+group) : <code>string</code> \| <code>Array.&lt;string&gt;</code>
<a name="exp_module_option-definition--OptionDefinition"></a>
### OptionDefinition ⏏
Describes a command-line option. Additionally, if generating a usage guide with [command-line-usage](https://github.com/75lb/command-line-usage) you could optionally add `description` and `typeLabel` properties to each definition.
**Kind**: Exported class
<a name="module_option-definition--OptionDefinition+name"></a>
#### option.name : <code>string</code>
The only required definition property is `name`, so the simplest working example is
```js
const optionDefinitions = [
{ name: 'file' },
{ name: 'depth' }
]
```
Where a `type` property is not specified it will default to `String`.
| # | Command line args | .parse() output |
| --- | -------------------- | ------------ |
| 1 | `--file` | `{ file: null }` |
| 2 | `--file lib.js` | `{ file: 'lib.js' }` |
| 3 | `--depth 2` | `{ depth: '2' }` |
Unicode option names and aliases are valid, for example:
```js
const optionDefinitions = [
{ name: 'один' },
{ name: '两' },
{ name: 'три', alias: 'т' }
]
```
**Kind**: instance property of [<code>OptionDefinition</code>](#exp_module_option-definition--OptionDefinition)
<a name="module_option-definition--OptionDefinition+type"></a>
#### option.type : <code>function</code>
The `type` value is a setter function (you receive the output from this), enabling you to be specific about the type and value received.
The most common values used are `String` (the default), `Number` and `Boolean` but you can use a custom function, for example:
```js
const fs = require('fs')
class FileDetails {
constructor (filename) {
this.filename = filename
this.exists = fs.existsSync(filename)
}
}
const cli = commandLineArgs([
{ name: 'file', type: filename => new FileDetails(filename) },
{ name: 'depth', type: Number }
])
```
| # | Command line args| .parse() output |
| --- | ----------------- | ------------ |
| 1 | `--file asdf.txt` | `{ file: { filename: 'asdf.txt', exists: false } }` |
The `--depth` option expects a `Number`. If no value was set, you will receive `null`.
| # | Command line args | .parse() output |
| --- | ----------------- | ------------ |
| 2 | `--depth` | `{ depth: null }` |
| 3 | `--depth 2` | `{ depth: 2 }` |
**Kind**: instance property of [<code>OptionDefinition</code>](#exp_module_option-definition--OptionDefinition)
**Default**: <code>String</code>
<a name="module_option-definition--OptionDefinition+alias"></a>
#### option.alias : <code>string</code>
getopt-style short option names. Can be any single character (unicode included) except a digit or hyphen.
```js
const optionDefinitions = [
{ name: 'hot', alias: 'h', type: Boolean },
{ name: 'discount', alias: 'd', type: Boolean },
{ name: 'courses', alias: 'c' , type: Number }
]
```
| # | Command line | .parse() output |
| --- | ------------ | ------------ |
| 1 | `-hcd` | `{ hot: true, courses: null, discount: true }` |
| 2 | `-hdc 3` | `{ hot: true, discount: true, courses: 3 }` |
**Kind**: instance property of [<code>OptionDefinition</code>](#exp_module_option-definition--OptionDefinition)
<a name="module_option-definition--OptionDefinition+multiple"></a>
#### option.multiple : <code>boolean</code>
Set this flag if the option takes a list of values. You will receive an array of values, each passed through the `type` function (if specified).
```js
const optionDefinitions = [
{ name: 'files', type: String, multiple: true }
]
```
Note, examples 1 and 3 below demonstrate "greedy" parsing which can be disabled by using `lazyMultiple`.
| # | Command line | .parse() output |
| --- | ------------ | ------------ |
| 1 | `--files one.js two.js` | `{ files: [ 'one.js', 'two.js' ] }` |
| 2 | `--files one.js --files two.js` | `{ files: [ 'one.js', 'two.js' ] }` |
| 3 | `--files *` | `{ files: [ 'one.js', 'two.js' ] }` |
**Kind**: instance property of [<code>OptionDefinition</code>](#exp_module_option-definition--OptionDefinition)
<a name="module_option-definition--OptionDefinition+lazyMultiple"></a>
#### option.lazyMultiple : <code>boolean</code>
Identical to `multiple` but with greedy parsing disabled.
```js
const optionDefinitions = [
{ name: 'files', lazyMultiple: true },
{ name: 'verbose', alias: 'v', type: Boolean, lazyMultiple: true }
]
```
| # | Command line | .parse() output |
| --- | ------------ | ------------ |
| 1 | `--files one.js --files two.js` | `{ files: [ 'one.js', 'two.js' ] }` |
| 2 | `-vvv` | `{ verbose: [ true, true, true ] }` |
**Kind**: instance property of [<code>OptionDefinition</code>](#exp_module_option-definition--OptionDefinition)
<a name="module_option-definition--OptionDefinition+defaultOption"></a>
#### option.defaultOption : <code>boolean</code>
Any values unaccounted for by an option definition will be set on the `defaultOption`. This flag is typically set on the most commonly-used option to make for more concise usage (i.e. `$ example *.js` instead of `$ example --files *.js`).
```js
const optionDefinitions = [
{ name: 'files', multiple: true, defaultOption: true }
]
```
| # | Command line | .parse() output |
| --- | ------------ | ------------ |
| 1 | `--files one.js two.js` | `{ files: [ 'one.js', 'two.js' ] }` |
| 2 | `one.js two.js` | `{ files: [ 'one.js', 'two.js' ] }` |
| 3 | `*` | `{ files: [ 'one.js', 'two.js' ] }` |
**Kind**: instance property of [<code>OptionDefinition</code>](#exp_module_option-definition--OptionDefinition)
<a name="module_option-definition--OptionDefinition+defaultValue"></a>
#### option.defaultValue : <code>\*</code>
An initial value for the option.
```js
const optionDefinitions = [
{ name: 'files', multiple: true, defaultValue: [ 'one.js' ] },
{ name: 'max', type: Number, defaultValue: 3 }
]
```
| # | Command line | .parse() output |
| --- | ------------ | ------------ |
| 1 | | `{ files: [ 'one.js' ], max: 3 }` |
| 2 | `--files two.js` | `{ files: [ 'two.js' ], max: 3 }` |
| 3 | `--max 4` | `{ files: [ 'one.js' ], max: 4 }` |
**Kind**: instance property of [<code>OptionDefinition</code>](#exp_module_option-definition--OptionDefinition)
<a name="module_option-definition--OptionDefinition+group"></a>
#### option.group : <code>string</code> \| <code>Array.&lt;string&gt;</code>
When your app has a large amount of options it makes sense to organise them in groups.
There are two automatic groups: `_all` (contains all options) and `_none` (contains options without a `group` specified in their definition).
```js
const optionDefinitions = [
{ name: 'verbose', group: 'standard' },
{ name: 'help', group: [ 'standard', 'main' ] },
{ name: 'compress', group: [ 'server', 'main' ] },
{ name: 'static', group: 'server' },
{ name: 'debug' }
]
```
<table>
<tr>
<th>#</th><th>Command Line</th><th>.parse() output</th>
</tr>
<tr>
<td>1</td><td><code>--verbose</code></td><td><pre><code>
{
_all: { verbose: true },
standard: { verbose: true }
}
</code></pre></td>
</tr>
<tr>
<td>2</td><td><code>--debug</code></td><td><pre><code>
{
_all: { debug: true },
_none: { debug: true }
}
</code></pre></td>
</tr>
<tr>
<td>3</td><td><code>--verbose --debug --compress</code></td><td><pre><code>
{
_all: {
verbose: true,
debug: true,
compress: true
},
standard: { verbose: true },
server: { compress: true },
main: { compress: true },
_none: { debug: true }
}
</code></pre></td>
</tr>
<tr>
<td>4</td><td><code>--compress</code></td><td><pre><code>
{
_all: { compress: true },
server: { compress: true },
main: { compress: true }
}
</code></pre></td>
</tr>
</table>
**Kind**: instance property of [<code>OptionDefinition</code>](#exp_module_option-definition--OptionDefinition)

82
node_modules/command-line-args/index.js generated vendored Normal file
View File

@ -0,0 +1,82 @@
'use strict'
/**
* @module command-line-args
*/
module.exports = commandLineArgs
/**
* Returns an object containing all option values set on the command line. By default it parses the global [`process.argv`](https://nodejs.org/api/process.html#process_process_argv) array.
*
* Parsing is strict by default - an exception is thrown if the user sets a singular option more than once or sets an unknown value or option (one without a valid [definition](https://github.com/75lb/command-line-args/blob/master/doc/option-definition.md)). To be more permissive, enabling [partial](https://github.com/75lb/command-line-args/wiki/Partial-mode-example) or [stopAtFirstUnknown](https://github.com/75lb/command-line-args/wiki/stopAtFirstUnknown) modes will return known options in the usual manner while collecting unknown arguments in a separate `_unknown` property.
*
* @param {module:definition[]} - An array of [OptionDefinition](https://github.com/75lb/command-line-args/blob/master/doc/option-definition.md) objects
* @param {object} [options] - Options.
* @param {string[]} [options.argv] - An array of strings which, if present will be parsed instead of `process.argv`.
* @param {boolean} [options.partial] - If `true`, an array of unknown arguments is returned in the `_unknown` property of the output.
* @param {boolean} [options.stopAtFirstUnknown] - If `true`, parsing will stop at the first unknown argument and the remaining arguments returned in `_unknown`. When set, `partial: true` is also implied.
* @param {boolean} [options.camelCase] - If `true`, options with hypenated names (e.g. `move-to`) will be returned in camel-case (e.g. `moveTo`).
* @returns {object}
* @throws `UNKNOWN_OPTION` If `options.partial` is false and the user set an undefined option. The `err.optionName` property contains the arg that specified an unknown option, e.g. `--one`.
* @throws `UNKNOWN_VALUE` If `options.partial` is false and the user set a value unaccounted for by an option definition. The `err.value` property contains the unknown value, e.g. `5`.
* @throws `ALREADY_SET` If a user sets a singular, non-multiple option more than once. The `err.optionName` property contains the option name that has already been set, e.g. `one`.
* @throws `INVALID_DEFINITIONS`
* - If an option definition is missing the required `name` property
* - If an option definition has a `type` value that's not a function
* - If an alias is numeric, a hyphen or a length other than 1
* - If an option definition name was used more than once
* - If an option definition alias was used more than once
* - If more than one option definition has `defaultOption: true`
* - If a `Boolean` option is also set as the `defaultOption`.
* @alias module:command-line-args
*/
function commandLineArgs (optionDefinitions, options) {
options = options || {}
if (options.stopAtFirstUnknown) options.partial = true
const Definitions = require('./lib/option-definitions')
optionDefinitions = Definitions.from(optionDefinitions)
const ArgvParser = require('./lib/argv-parser')
const parser = new ArgvParser(optionDefinitions, {
argv: options.argv,
stopAtFirstUnknown: options.stopAtFirstUnknown
})
const Option = require('./lib/option')
const OutputClass = optionDefinitions.isGrouped() ? require('./lib/output-grouped') : require('./lib/output')
const output = new OutputClass(optionDefinitions)
/* Iterate the parser setting each known value to the output. Optionally, throw on unknowns. */
for (const argInfo of parser) {
const arg = argInfo.subArg || argInfo.arg
if (!options.partial) {
if (argInfo.event === 'unknown_value') {
const err = new Error(`Unknown value: ${arg}`)
err.name = 'UNKNOWN_VALUE'
err.value = arg
throw err
} else if (argInfo.event === 'unknown_option') {
const err = new Error(`Unknown option: ${arg}`)
err.name = 'UNKNOWN_OPTION'
err.optionName = arg
throw err
}
}
let option
if (output.has(argInfo.name)) {
option = output.get(argInfo.name)
} else {
option = Option.create(argInfo.def)
output.set(argInfo.name, option)
}
if (argInfo.name === '_unknown') {
option.set(arg)
} else {
option.set(argInfo.value)
}
}
return output.toObject({ skipUnknown: !options.partial, camelCase: options.camelCase })
}

139
node_modules/command-line-args/lib/argv-parser.js generated vendored Normal file
View File

@ -0,0 +1,139 @@
'use strict'
const argvTools = require('argv-tools')
/**
* @module argv-parser
*/
/**
* @alias module:argv-parser
*/
class ArgvParser {
/**
* @param {OptionDefinitions} - Definitions array
* @param {object} [options] - Options
* @param {string[]} [options.argv] - Overrides `process.argv`
* @param {boolean} [options.stopAtFirstUnknown] -
*/
constructor (definitions, options) {
this.options = Object.assign({}, options)
const Definitions = require('./option-definitions')
/**
* Option Definitions
*/
this.definitions = Definitions.from(definitions)
/**
* Argv
*/
this.argv = argvTools.ArgvArray.from(this.options.argv)
if (this.argv.hasCombinedShortOptions()) {
const findReplace = require('find-replace')
findReplace(this.argv, argvTools.re.combinedShort, arg => {
arg = arg.slice(1)
return arg.split('').map(letter => ({ origArg: `-${arg}`, arg: '-' + letter }))
})
}
}
/**
* Yields one `{ event, name, value, arg, def }` argInfo object for each arg in `process.argv` (or `options.argv`).
*/
* [Symbol.iterator] () {
const definitions = this.definitions
const t = require('typical')
let def
let value
let name
let event
let singularDefaultSet = false
let unknownFound = false
let origArg
for (let arg of this.argv) {
if (t.isPlainObject(arg)) {
origArg = arg.origArg
arg = arg.arg
}
if (unknownFound && this.options.stopAtFirstUnknown) {
yield { event: 'unknown_value', arg, name: '_unknown', value: undefined }
continue
}
/* handle long or short option */
if (argvTools.isOption(arg)) {
def = definitions.get(arg)
value = undefined
if (def) {
value = def.isBoolean() ? true : null
event = 'set'
} else {
event = 'unknown_option'
}
/* handle --option-value notation */
} else if (argvTools.isOptionEqualsNotation(arg)) {
const matches = arg.match(argvTools.re.optEquals)
def = definitions.get(matches[1])
if (def) {
if (def.isBoolean()) {
yield { event: 'unknown_value', arg, name: '_unknown', value, def }
event = 'set'
value = true
} else {
event = 'set'
value = matches[2]
}
} else {
event = 'unknown_option'
}
/* handle value */
} else if (argvTools.isValue(arg)) {
if (def) {
value = arg
event = 'set'
} else {
/* get the defaultOption */
def = this.definitions.getDefault()
if (def && !singularDefaultSet) {
value = arg
event = 'set'
} else {
event = 'unknown_value'
def = undefined
}
}
}
name = def ? def.name : '_unknown'
const argInfo = { event, arg, name, value, def }
if (origArg) {
argInfo.subArg = arg
argInfo.arg = origArg
}
yield argInfo
/* unknownFound logic */
if (name === '_unknown') unknownFound = true
/* singularDefaultSet logic */
if (def && def.defaultOption && !def.isMultiple() && event === 'set') singularDefaultSet = true
/* reset values once consumed and yielded */
if (def && def.isBoolean()) def = undefined
/* reset the def if it's a singular which has been set */
if (def && !def.multiple && t.isDefined(value) && value !== null) {
def = undefined
}
value = undefined
event = undefined
name = undefined
origArg = undefined
}
}
}
module.exports = ArgvParser

265
node_modules/command-line-args/lib/option-definition.js generated vendored Normal file
View File

@ -0,0 +1,265 @@
'use strict'
const t = require('typical')
/**
* @module option-definition
*/
/**
* Describes a command-line option. Additionally, if generating a usage guide with [command-line-usage](https://github.com/75lb/command-line-usage) you could optionally add `description` and `typeLabel` properties to each definition.
*
* @alias module:option-definition
* @typicalname option
*/
class OptionDefinition {
constructor (definition) {
/**
* The only required definition property is `name`, so the simplest working example is
* ```js
* const optionDefinitions = [
* { name: 'file' },
* { name: 'depth' }
* ]
* ```
*
* Where a `type` property is not specified it will default to `String`.
*
* | # | Command line args | .parse() output |
* | --- | -------------------- | ------------ |
* | 1 | `--file` | `{ file: null }` |
* | 2 | `--file lib.js` | `{ file: 'lib.js' }` |
* | 3 | `--depth 2` | `{ depth: '2' }` |
*
* Unicode option names and aliases are valid, for example:
* ```js
* const optionDefinitions = [
* { name: 'один' },
* { name: '两' },
* { name: 'три', alias: 'т' }
* ]
* ```
* @type {string}
*/
this.name = definition.name
/**
* The `type` value is a setter function (you receive the output from this), enabling you to be specific about the type and value received.
*
* The most common values used are `String` (the default), `Number` and `Boolean` but you can use a custom function, for example:
*
* ```js
* const fs = require('fs')
*
* class FileDetails {
* constructor (filename) {
* this.filename = filename
* this.exists = fs.existsSync(filename)
* }
* }
*
* const cli = commandLineArgs([
* { name: 'file', type: filename => new FileDetails(filename) },
* { name: 'depth', type: Number }
* ])
* ```
*
* | # | Command line args| .parse() output |
* | --- | ----------------- | ------------ |
* | 1 | `--file asdf.txt` | `{ file: { filename: 'asdf.txt', exists: false } }` |
*
* The `--depth` option expects a `Number`. If no value was set, you will receive `null`.
*
* | # | Command line args | .parse() output |
* | --- | ----------------- | ------------ |
* | 2 | `--depth` | `{ depth: null }` |
* | 3 | `--depth 2` | `{ depth: 2 }` |
*
* @type {function}
* @default String
*/
this.type = definition.type || String
/**
* getopt-style short option names. Can be any single character (unicode included) except a digit or hyphen.
*
* ```js
* const optionDefinitions = [
* { name: 'hot', alias: 'h', type: Boolean },
* { name: 'discount', alias: 'd', type: Boolean },
* { name: 'courses', alias: 'c' , type: Number }
* ]
* ```
*
* | # | Command line | .parse() output |
* | --- | ------------ | ------------ |
* | 1 | `-hcd` | `{ hot: true, courses: null, discount: true }` |
* | 2 | `-hdc 3` | `{ hot: true, discount: true, courses: 3 }` |
*
* @type {string}
*/
this.alias = definition.alias
/**
* Set this flag if the option takes a list of values. You will receive an array of values, each passed through the `type` function (if specified).
*
* ```js
* const optionDefinitions = [
* { name: 'files', type: String, multiple: true }
* ]
* ```
*
* Note, examples 1 and 3 below demonstrate "greedy" parsing which can be disabled by using `lazyMultiple`.
*
* | # | Command line | .parse() output |
* | --- | ------------ | ------------ |
* | 1 | `--files one.js two.js` | `{ files: [ 'one.js', 'two.js' ] }` |
* | 2 | `--files one.js --files two.js` | `{ files: [ 'one.js', 'two.js' ] }` |
* | 3 | `--files *` | `{ files: [ 'one.js', 'two.js' ] }` |
*
* @type {boolean}
*/
this.multiple = definition.multiple
/**
* Identical to `multiple` but with greedy parsing disabled.
*
* ```js
* const optionDefinitions = [
* { name: 'files', lazyMultiple: true },
* { name: 'verbose', alias: 'v', type: Boolean, lazyMultiple: true }
* ]
* ```
*
* | # | Command line | .parse() output |
* | --- | ------------ | ------------ |
* | 1 | `--files one.js --files two.js` | `{ files: [ 'one.js', 'two.js' ] }` |
* | 2 | `-vvv` | `{ verbose: [ true, true, true ] }` |
*
* @type {boolean}
*/
this.lazyMultiple = definition.lazyMultiple
/**
* Any values unaccounted for by an option definition will be set on the `defaultOption`. This flag is typically set on the most commonly-used option to make for more concise usage (i.e. `$ example *.js` instead of `$ example --files *.js`).
*
* ```js
* const optionDefinitions = [
* { name: 'files', multiple: true, defaultOption: true }
* ]
* ```
*
* | # | Command line | .parse() output |
* | --- | ------------ | ------------ |
* | 1 | `--files one.js two.js` | `{ files: [ 'one.js', 'two.js' ] }` |
* | 2 | `one.js two.js` | `{ files: [ 'one.js', 'two.js' ] }` |
* | 3 | `*` | `{ files: [ 'one.js', 'two.js' ] }` |
*
* @type {boolean}
*/
this.defaultOption = definition.defaultOption
/**
* An initial value for the option.
*
* ```js
* const optionDefinitions = [
* { name: 'files', multiple: true, defaultValue: [ 'one.js' ] },
* { name: 'max', type: Number, defaultValue: 3 }
* ]
* ```
*
* | # | Command line | .parse() output |
* | --- | ------------ | ------------ |
* | 1 | | `{ files: [ 'one.js' ], max: 3 }` |
* | 2 | `--files two.js` | `{ files: [ 'two.js' ], max: 3 }` |
* | 3 | `--max 4` | `{ files: [ 'one.js' ], max: 4 }` |
*
* @type {*}
*/
this.defaultValue = definition.defaultValue
/**
* When your app has a large amount of options it makes sense to organise them in groups.
*
* There are two automatic groups: `_all` (contains all options) and `_none` (contains options without a `group` specified in their definition).
*
* ```js
* const optionDefinitions = [
* { name: 'verbose', group: 'standard' },
* { name: 'help', group: [ 'standard', 'main' ] },
* { name: 'compress', group: [ 'server', 'main' ] },
* { name: 'static', group: 'server' },
* { name: 'debug' }
* ]
* ```
*
*<table>
* <tr>
* <th>#</th><th>Command Line</th><th>.parse() output</th>
* </tr>
* <tr>
* <td>1</td><td><code>--verbose</code></td><td><pre><code>
*{
* _all: { verbose: true },
* standard: { verbose: true }
*}
*</code></pre></td>
* </tr>
* <tr>
* <td>2</td><td><code>--debug</code></td><td><pre><code>
*{
* _all: { debug: true },
* _none: { debug: true }
*}
*</code></pre></td>
* </tr>
* <tr>
* <td>3</td><td><code>--verbose --debug --compress</code></td><td><pre><code>
*{
* _all: {
* verbose: true,
* debug: true,
* compress: true
* },
* standard: { verbose: true },
* server: { compress: true },
* main: { compress: true },
* _none: { debug: true }
*}
*</code></pre></td>
* </tr>
* <tr>
* <td>4</td><td><code>--compress</code></td><td><pre><code>
*{
* _all: { compress: true },
* server: { compress: true },
* main: { compress: true }
*}
*</code></pre></td>
* </tr>
*</table>
*
* @type {string|string[]}
*/
this.group = definition.group
/* pick up any remaining properties */
for (let prop in definition) {
if (!this[prop]) this[prop] = definition[prop]
}
}
isBoolean () {
return this.type === Boolean || (t.isFunction(this.type) && this.type.name === 'Boolean')
}
isMultiple () {
return this.multiple || this.lazyMultiple
}
static create (def) {
const result = new this(def)
return result
}
}
module.exports = OptionDefinition

View File

@ -0,0 +1,170 @@
'use strict'
const arrayify = require('array-back')
const argvTools = require('argv-tools')
const t = require('typical')
/**
* @module option-definitions
*/
/**
* @alias module:option-definitions
*/
class Definitions extends Array {
/**
* validate option definitions
* @returns {string}
*/
validate () {
const someHaveNoName = this.some(def => !def.name)
if (someHaveNoName) {
halt(
'INVALID_DEFINITIONS',
'Invalid option definitions: the `name` property is required on each definition'
)
}
const someDontHaveFunctionType = this.some(def => def.type && typeof def.type !== 'function')
if (someDontHaveFunctionType) {
halt(
'INVALID_DEFINITIONS',
'Invalid option definitions: the `type` property must be a setter fuction (default: `Boolean`)'
)
}
let invalidOption
const numericAlias = this.some(def => {
invalidOption = def
return t.isDefined(def.alias) && t.isNumber(def.alias)
})
if (numericAlias) {
halt(
'INVALID_DEFINITIONS',
'Invalid option definition: to avoid ambiguity an alias cannot be numeric [--' + invalidOption.name + ' alias is -' + invalidOption.alias + ']'
)
}
const multiCharacterAlias = this.some(def => {
invalidOption = def
return t.isDefined(def.alias) && def.alias.length !== 1
})
if (multiCharacterAlias) {
halt(
'INVALID_DEFINITIONS',
'Invalid option definition: an alias must be a single character'
)
}
const hypenAlias = this.some(def => {
invalidOption = def
return def.alias === '-'
})
if (hypenAlias) {
halt(
'INVALID_DEFINITIONS',
'Invalid option definition: an alias cannot be "-"'
)
}
const duplicateName = hasDuplicates(this.map(def => def.name))
if (duplicateName) {
halt(
'INVALID_DEFINITIONS',
'Two or more option definitions have the same name'
)
}
const duplicateAlias = hasDuplicates(this.map(def => def.alias))
if (duplicateAlias) {
halt(
'INVALID_DEFINITIONS',
'Two or more option definitions have the same alias'
)
}
const duplicateDefaultOption = hasDuplicates(this.map(def => def.defaultOption))
if (duplicateDefaultOption) {
halt(
'INVALID_DEFINITIONS',
'Only one option definition can be the defaultOption'
)
}
const defaultBoolean = this.some(def => {
invalidOption = def
return def.isBoolean() && def.defaultOption
})
if (defaultBoolean) {
halt(
'INVALID_DEFINITIONS',
`A boolean option ["${invalidOption.name}"] can not also be the defaultOption.`
)
}
}
/**
* Get definition by option arg (e.g. `--one` or `-o`)
* @param {string}
* @returns {Definition}
*/
get (arg) {
if (argvTools.isOption(arg)) {
return argvTools.re.short.test(arg)
? this.find(def => def.alias === argvTools.getOptionName(arg))
: this.find(def => def.name === argvTools.getOptionName(arg))
} else {
return this.find(def => def.name === arg)
}
}
getDefault () {
return this.find(def => def.defaultOption === true)
}
isGrouped () {
return this.some(def => def.group)
}
whereGrouped () {
return this.filter(containsValidGroup)
}
whereNotGrouped () {
return this.filter(def => !containsValidGroup(def))
}
whereDefaultValueSet () {
return this.filter(def => t.isDefined(def.defaultValue))
}
static from (definitions) {
if (definitions instanceof this) return definitions
const Definition = require('./option-definition')
const result = super.from(arrayify(definitions), def => Definition.create(def))
result.validate()
return result
}
}
function halt (name, message) {
const err = new Error(message)
err.name = name
throw err
}
function containsValidGroup (def) {
return arrayify(def.group).some(group => group)
}
function hasDuplicates (array) {
const items = {}
for (let i = 0; i < array.length; i++) {
const value = array[i]
if (items[value]) {
return true
} else {
if (t.isDefined(value)) items[value] = true
}
}
}
module.exports = Definitions

14
node_modules/command-line-args/lib/option-flag.js generated vendored Normal file
View File

@ -0,0 +1,14 @@
'use strict'
const Option = require('./option')
class FlagOption extends Option {
set (val) {
super.set(true)
}
static create (def) {
return new this(def)
}
}
module.exports = FlagOption

83
node_modules/command-line-args/lib/option.js generated vendored Normal file
View File

@ -0,0 +1,83 @@
'use strict'
const _value = new WeakMap()
const arrayify = require('array-back')
const t = require('typical')
const Definition = require('./option-definition')
/**
* Encapsulates behaviour (defined by an OptionDefinition) when setting values
*/
class Option {
constructor (definition) {
this.definition = new Definition(definition)
this.state = null /* set or default */
this.resetToDefault()
}
get () {
return _value.get(this)
}
set (val) {
this._set(val, 'set')
}
_set (val, state) {
const def = this.definition
if (def.isMultiple()) {
/* don't add null or undefined to a multiple */
if (val !== null && val !== undefined) {
const arr = this.get()
if (this.state === 'default') arr.length = 0
arr.push(def.type(val))
this.state = state
}
} else {
/* throw if already set on a singlar defaultOption */
if (!def.isMultiple() && this.state === 'set') {
const err = new Error(`Singular option already set [${this.definition.name}=${this.get()}]`)
err.name = 'ALREADY_SET'
err.value = val
err.optionName = def.name
throw err
} else if (val === null || val === undefined) {
_value.set(this, val)
// /* required to make 'partial: defaultOption with value equal to defaultValue 2' pass */
// if (!(def.defaultOption && !def.isMultiple())) {
// this.state = state
// }
} else {
_value.set(this, def.type(val))
this.state = state
}
}
}
resetToDefault () {
if (t.isDefined(this.definition.defaultValue)) {
if (this.definition.isMultiple()) {
_value.set(this, arrayify(this.definition.defaultValue).slice())
} else {
_value.set(this, this.definition.defaultValue)
}
} else {
if (this.definition.isMultiple()) {
_value.set(this, [])
} else {
_value.set(this, null)
}
}
this.state = 'default'
}
static create (definition) {
definition = new Definition(definition)
if (definition.isBoolean()) {
return require('./option-flag').create(definition)
} else {
return new this(definition)
}
}
}
module.exports = Option

41
node_modules/command-line-args/lib/output-grouped.js generated vendored Normal file
View File

@ -0,0 +1,41 @@
'use strict'
const Output = require('./output')
class GroupedOutput extends Output {
toObject (options) {
const arrayify = require('array-back')
const t = require('typical')
const camelCase = require('lodash.camelcase')
const superOutputNoCamel = super.toObject({ skipUnknown: options.skipUnknown })
const superOutput = super.toObject(options)
const unknown = superOutput._unknown
delete superOutput._unknown
const grouped = {
_all: superOutput
}
if (unknown && unknown.length) grouped._unknown = unknown
this.definitions.whereGrouped().forEach(def => {
const name = options.camelCase ? camelCase(def.name) : def.name
const outputValue = superOutputNoCamel[def.name]
for (const groupName of arrayify(def.group)) {
grouped[groupName] = grouped[groupName] || {}
if (t.isDefined(outputValue)) {
grouped[groupName][name] = outputValue
}
}
})
this.definitions.whereNotGrouped().forEach(def => {
const name = options.camelCase ? camelCase(def.name) : def.name
const outputValue = superOutputNoCamel[def.name]
if (t.isDefined(outputValue)) {
if (!grouped._none) grouped._none = {}
grouped._none[name] = outputValue
}
})
return grouped
}
}
module.exports = GroupedOutput

39
node_modules/command-line-args/lib/output.js generated vendored Normal file
View File

@ -0,0 +1,39 @@
'use strict'
const Option = require('./option')
/**
* A map of { DefinitionNameString: Option }. By default, an Output has an `_unknown` property and any options with defaultValues.
*/
class Output extends Map {
constructor (definitions) {
super()
const Definitions = require('./option-definitions')
/**
* @type {OptionDefinitions}
*/
this.definitions = Definitions.from(definitions)
/* by default, an Output has an `_unknown` property and any options with defaultValues */
this.set('_unknown', Option.create({ name: '_unknown', multiple: true }))
for (const def of this.definitions.whereDefaultValueSet()) {
this.set(def.name, Option.create(def))
}
}
toObject (options) {
const camelCase = require('lodash.camelcase')
options = options || {}
const output = {}
for (const item of this) {
const name = options.camelCase && item[0] !== '_unknown' ? camelCase(item[0]) : item[0]
const option = item[1]
if (name === '_unknown' && !option.get().length) continue
output[name] = option.get()
}
if (options.skipUnknown) delete output._unknown
return output
}
}
module.exports = Output

77
node_modules/command-line-args/package.json generated vendored Normal file
View File

@ -0,0 +1,77 @@
{
"_from": "command-line-args",
"_id": "command-line-args@5.0.2",
"_inBundle": false,
"_integrity": "sha512-/qPcbL8zpqg53x4rAaqMFlRV4opN3pbla7I7k9x8kyOBMQoGT6WltjN6sXZuxOXw6DgdK7Ad+ijYS5gjcr7vlA==",
"_location": "/command-line-args",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "command-line-args",
"name": "command-line-args",
"escapedName": "command-line-args",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.0.2.tgz",
"_shasum": "c4e56b016636af1323cf485aa25c3cb203dfbbe4",
"_spec": "command-line-args",
"_where": "/home/wn/workspace-node/PiAlive",
"author": {
"name": "Lloyd Brookes",
"email": "75pound@gmail.com"
},
"bugs": {
"url": "https://github.com/75lb/command-line-args/issues"
},
"bundleDependencies": false,
"dependencies": {
"argv-tools": "^0.1.1",
"array-back": "^2.0.0",
"find-replace": "^2.0.1",
"lodash.camelcase": "^4.3.0",
"typical": "^2.6.1"
},
"deprecated": false,
"description": "A mature, feature-complete library to parse command-line options.",
"devDependencies": {
"coveralls": "^3.0.0",
"jsdoc-to-markdown": "^4.0.1",
"test-runner": "^0.5.0"
},
"engines": {
"node": ">=4.0.0"
},
"homepage": "https://github.com/75lb/command-line-args#readme",
"keywords": [
"argv",
"parse",
"argument",
"args",
"option",
"options",
"parser",
"parsing",
"cli",
"command",
"line"
],
"license": "MIT",
"name": "command-line-args",
"repository": {
"type": "git",
"url": "git+https://github.com/75lb/command-line-args.git"
},
"scripts": {
"cover": "istanbul cover ./node_modules/.bin/test-runner test/*.js test/internals/*.js && cat coverage/lcov.info | ./node_modules/.bin/coveralls #&& rm -rf coverage; echo",
"docs": "jsdoc2md index.js > doc/API.md && jsdoc2md lib/option-definition.js > doc/option-definition.md",
"test": "test-runner test/*.js test/internals/*.js"
},
"version": "5.0.2"
}

38
node_modules/command-line-args/test/alias.js generated vendored Normal file
View 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
View 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
View 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
View 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
View 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
View 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: [ './' ]
})
})

View 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' ])
})

View 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'
)
})

View 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'
)
})

View 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
View 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' ]
})
})

View 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' }
])
})

View 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 ])
})

View 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' } ])
})
})

View 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 ])
})

View 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')
})

View 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
View 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
View 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
View 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
View 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
View 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
View 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' ]
})
})

View 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
View 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
View 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
View 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
View 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
View 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' }
)
})