change approach again

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

3
node_modules/command-line-args/.npmignore generated vendored Normal file
View File

@ -0,0 +1,3 @@
tmp
.coveralls.yml
coverage

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

@ -0,0 +1,7 @@
language: node_js
node_js:
- 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-17 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.

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

@ -0,0 +1,374 @@
[![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)
# command-line-args
A mature, feature-complete library to parse command-line options.
*If your app requires a git-like command interface, consider using [command-line-commands](https://github.com/75lb/command-line-commands).*
## Synopsis
You can set options using the main notation standards (getopt, getopt_long, etc.). 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 describe the options your app accepts (see [option definitions](#optiondefinition-)).
```js
const commandLineArgs = require('command-line-args')
const optionDefinitions = [
{ name: 'verbose', alias: 'v', type: Boolean },
{ name: 'src', type: String, multiple: true, defaultOption: true },
{ name: 'timeout', alias: 't', type: Number }
]
```
The [`type`](#optiontype--function) property is a setter function (the value supplied is passed through this), giving you full control over the value received.
Next, parse the options using [commandLineArgs()](#commandlineargsdefinitions-argv--object-):
```js
const options = commandLineArgs(optionDefinitions)
```
`options` now looks like this:
```js
{
files: [
'one.js',
'two.js'
],
verbose: true,
timeout: 1000
}
```
When dealing with large amounts of options it often makes sense to [group](#optiongroup--string--arraystring) them.
A usage guide can be generated using [command-line-usage](https://github.com/75lb/command-line-usage), for example:
![usage](https://raw.githubusercontent.com/75lb/command-line-usage/master/example/screens/footer.png)
### Notation rules
Notation rules for setting command-line options.
* Argument order is insignificant. Whether you set `--example` at the beginning or end of the arg list makes no difference.
* Options with a [type](#optiontype--function) of `Boolean` do not need to supply a value. Setting `--flag` or `-f` will set that option's value to `true`. This is the only [type](#optiontype--function) with special behaviour.
* Three ways to set an option value
* `--option value`
* `--option=value`
* `-o value`
* Two ways to a set list of values (on options with [multiple](#optionmultiple--boolean) set)
* `--list one two three`
* `--list one --list two --list three`
* Short options ([alias](#optionalias--string)) can be set in groups. The following are equivalent:
* `-a -b -c`
* `-abc`
### Ambiguous values
Imagine we are using "grep-tool" to search for the string `'-f'`:
```
$ grep-tool --search -f
```
We have an issue here: command-line-args will assume we are setting two options (`--search` and `-f`). In actuality, we are passing one option (`--search`) and one value (`-f`). In cases like this, avoid ambiguity by using `--option=value` notation:
```
$ grep-tool --search=-f
```
### Partial parsing
By default, if the user sets an option without a valid [definition](#exp_module_definition--OptionDefinition) an `UNKNOWN_OPTION` exception is thrown. However, in some cases you may only be interested in a subset of the options wishing to pass the remainder to another library. See [here](https://github.com/75lb/command-line-args/blob/master/example/mocha.js) for a example showing where this might be necessary.
To enable partial parsing, set `partial: true` in the method options:
```js
const optionDefinitions = [
{ name: 'value', type: Number }
]
const options = commandLineArgs(optionDefinitions, { partial: true })
```
Now, should any unknown args be passed at the command line:
```
$ example --milk --value 2 --bread cheese
```
They will be returned in the `_unknown` property of the `commandLineArgs` output with no exceptions thrown:
```js
{
value: 2,
_unknown: [ '--milk', '--bread', 'cheese']
}
```
## Install
```sh
$ npm install command-line-args --save
```
# API Reference
<a name="exp_module_command-line-args--commandLineArgs"></a>
### commandLineArgs(optionDefinitions, [options]) ⇒ <code>object</code> ⏏
Returns an object containing all options set on the command line. By default it parses the global [`process.argv`](https://nodejs.org/api/process.html#process_process_argv) array.
By default, an exception is thrown if the user sets an unknown option (one without a valid [definition](#exp_module_definition--OptionDefinition)). To enable __partial parsing__, invoke `commandLineArgs` with the `partial` option - all unknown arguments will be returned in the `_unknown` property.
**Kind**: Exported function
**Throws**:
- `UNKNOWN_OPTION` if `options.partial` is false and the user set an undefined option
- `NAME_MISSING` if an option definition is missing the required `name` property
- `INVALID_TYPE` if an option definition has a `type` value that's not a function
- `INVALID_ALIAS` if an alias is numeric, a hyphen or a length other than 1
- `DUPLICATE_NAME` if an option definition name was used more than once
- `DUPLICATE_ALIAS` if an option definition alias was used more than once
- `DUPLICATE_DEFAULT_OPTION` if more than one option definition has `defaultOption: true`
| Param | Type | Description |
| --- | --- | --- |
| optionDefinitions | <code>[Array.&lt;definition&gt;](#module_definition)</code> | An array of [OptionDefinition](#exp_module_definition--OptionDefinition) objects |
| [options] | <code>object</code> | Options. |
| [options.argv] | <code>Array.&lt;string&gt;</code> | An array of strings, which if passed 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. |
<a name="exp_module_definition--OptionDefinition"></a>
## OptionDefinition ⏏
Describes a command-line option. Additionally, you can add `description` and `typeLabel` properties and make use of [command-line-usage](https://github.com/75lb/command-line-usage).
**Kind**: Exported class
* [OptionDefinition](#exp_module_definition--OptionDefinition) ⏏
* [.name](#module_definition--OptionDefinition.OptionDefinition+name) : <code>string</code>
* [.type](#module_definition--OptionDefinition.OptionDefinition+type) : <code>function</code>
* [.alias](#module_definition--OptionDefinition.OptionDefinition+alias) : <code>string</code>
* [.multiple](#module_definition--OptionDefinition.OptionDefinition+multiple) : <code>boolean</code>
* [.defaultOption](#module_definition--OptionDefinition.OptionDefinition+defaultOption) : <code>boolean</code>
* [.defaultValue](#module_definition--OptionDefinition.OptionDefinition+defaultValue) : <code>\*</code>
* [.group](#module_definition--OptionDefinition.OptionDefinition+group) : <code>string</code> \| <code>Array.&lt;string&gt;</code>
<a name="module_definition--OptionDefinition.OptionDefinition+name"></a>
### option.name : <code>string</code>
The only required definition property is `name`, so the simplest working example is
```js
[
{ name: "file" },
{ name: "verbose" },
{ name: "depth"}
]
```
In this case, the value of each option will be either a Boolean or string.
| # | Command line args | .parse() output |
| --- | -------------------- | ------------ |
| 1 | `--file` | `{ file: true }` |
| 2 | `--file lib.js --verbose` | `{ file: "lib.js", verbose: true }` |
| 3 | `--verbose very` | `{ verbose: "very" }` |
| 4 | `--depth 2` | `{ depth: "2" }` |
Unicode option names and aliases are valid, for example:
```js
[
{ name: 'один' },
{ name: '两' },
{ name: 'три', alias: 'т' }
]
```
**Kind**: instance property of <code>[OptionDefinition](#exp_module_definition--OptionDefinition)</code>
<a name="module_definition--OptionDefinition.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.
You can use a class, if you like:
```js
const fs = require('fs')
function FileDetails(filename){
if (!(this instanceof FileDetails)) return new FileDetails(filename)
this.filename = filename
this.exists = fs.existsSync(filename)
}
const cli = commandLineArgs([
{ name: 'file', type: FileDetails },
{ 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](#exp_module_definition--OptionDefinition)</code>
**Default**: <code>String</code>
<a name="module_definition--OptionDefinition.OptionDefinition+alias"></a>
### option.alias : <code>string</code>
getopt-style short option names. Can be any single character (unicode included) except a digit or hypen.
```js
[
{ 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](#exp_module_definition--OptionDefinition)</code>
<a name="module_definition--OptionDefinition.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
[
{ name: "files", type: String, multiple: true }
]
```
| # | 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](#exp_module_definition--OptionDefinition)</code>
<a name="module_definition--OptionDefinition.OptionDefinition+defaultOption"></a>
### option.defaultOption : <code>boolean</code>
Any unclaimed command-line args will be set on this option. This flag is typically set on the most commonly-used option to make for more concise usage (i.e. `$ myapp *.js` instead of `$ myapp --files *.js`).
```js
[
{ name: "files", type: String, 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](#exp_module_definition--OptionDefinition)</code>
<a name="module_definition--OptionDefinition.OptionDefinition+defaultValue"></a>
### option.defaultValue : <code>\*</code>
An initial value for the option.
```js
[
{ name: "files", type: String, 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](#exp_module_definition--OptionDefinition)</code>
<a name="module_definition--OptionDefinition.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
[
{ 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](#exp_module_definition--OptionDefinition)</code>
* * *
&copy; 2014-17 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown).

24
node_modules/command-line-args/bin/cli.js generated vendored Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env node
'use strict'
const commandLineArgs = require('../')
const os = require('os')
const fs = require('fs')
const path = require('path')
const tmpPath = path.join(os.tmpdir(), Date.now() + '-cla.js')
process.stdin
.pipe(fs.createWriteStream(tmpPath))
.on('close', parseCla)
function parseCla () {
const cliOptions = require(tmpPath)
fs.unlinkSync(tmpPath)
try {
console.log(commandLineArgs(cliOptions))
} catch (err) {
console.error(err.message)
process.exitCode = 1
}
}

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

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

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

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

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

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

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

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

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

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

135
node_modules/command-line-args/jsdoc2md/README.hbs generated vendored Normal file
View File

@ -0,0 +1,135 @@
[![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)
# command-line-args
A mature, feature-complete library to parse command-line options.
*If your app requires a git-like command interface, consider using [command-line-commands](https://github.com/75lb/command-line-commands).*
## Synopsis
You can set options using the main notation standards (getopt, getopt_long, etc.). 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 describe the options your app accepts (see [option definitions](#optiondefinition-)).
```js
const commandLineArgs = require('command-line-args')
const optionDefinitions = [
{ name: 'verbose', alias: 'v', type: Boolean },
{ name: 'src', type: String, multiple: true, defaultOption: true },
{ name: 'timeout', alias: 't', type: Number }
]
```
The [`type`](#optiontype--function) property is a setter function (the value supplied is passed through this), giving you full control over the value received.
Next, parse the options using [commandLineArgs()](#commandlineargsdefinitions-argv--object-):
```js
const options = commandLineArgs(optionDefinitions)
```
`options` now looks like this:
```js
{
files: [
'one.js',
'two.js'
],
verbose: true,
timeout: 1000
}
```
When dealing with large amounts of options it often makes sense to [group](#optiongroup--string--arraystring) them.
A usage guide can be generated using [command-line-usage](https://github.com/75lb/command-line-usage), for example:
![usage](https://raw.githubusercontent.com/75lb/command-line-usage/master/example/screens/footer.png)
### Notation rules
Notation rules for setting command-line options.
* Argument order is insignificant. Whether you set `--example` at the beginning or end of the arg list makes no difference.
* Options with a [type](#optiontype--function) of `Boolean` do not need to supply a value. Setting `--flag` or `-f` will set that option's value to `true`. This is the only [type](#optiontype--function) with special behaviour.
* Three ways to set an option value
* `--option value`
* `--option=value`
* `-o value`
* Two ways to a set list of values (on options with [multiple](#optionmultiple--boolean) set)
* `--list one two three`
* `--list one --list two --list three`
* Short options ([alias](#optionalias--string)) can be set in groups. The following are equivalent:
* `-a -b -c`
* `-abc`
### Ambiguous values
Imagine we are using "grep-tool" to search for the string `'-f'`:
```
$ grep-tool --search -f
```
We have an issue here: command-line-args will assume we are setting two options (`--search` and `-f`). In actuality, we are passing one option (`--search`) and one value (`-f`). In cases like this, avoid ambiguity by using `--option=value` notation:
```
$ grep-tool --search=-f
```
### Partial parsing
By default, if the user sets an option without a valid [definition](#exp_module_definition--OptionDefinition) an `UNKNOWN_OPTION` exception is thrown. However, in some cases you may only be interested in a subset of the options wishing to pass the remainder to another library. See [here](https://github.com/75lb/command-line-args/blob/master/example/mocha.js) for a example showing where this might be necessary.
To enable partial parsing, set `partial: true` in the method options:
```js
const optionDefinitions = [
{ name: 'value', type: Number }
]
const options = commandLineArgs(optionDefinitions, { partial: true })
```
Now, should any unknown args be passed at the command line:
```
$ example --milk --value 2 --bread cheese
```
They will be returned in the `_unknown` property of the `commandLineArgs` output with no exceptions thrown:
```js
{
value: 2,
_unknown: [ '--milk', '--bread', 'cheese']
}
```
## Install
```sh
$ npm install command-line-args --save
```
# API Reference
{{#module name="command-line-args"}}
{{>body~}}
{{>member-index~}}
{{>separator~}}
{{>members~}}
{{/module}}
{{#class name="OptionDefinition"}}{{>docs}}{{/class}}
* * *
&copy; 2014-17 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown).

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

@ -0,0 +1,96 @@
'use strict'
const arrayify = require('array-back')
const option = require('./option')
/**
* Handles parsing different argv notations
*
* @module argv
* @private
*/
class Argv extends Array {
load (argv) {
if (argv) {
argv = arrayify(argv)
} else {
/* if no argv supplied, assume we are parsing process.argv */
argv = process.argv.slice(0)
argv.splice(0, 2)
}
argv.forEach(arg => this.push(String(arg)))
}
clear () {
this.length = 0
}
/**
* expand --option=value style args. The value is clearly marked to indicate it is definitely a value (which would otherwise be unclear if the value is `--value`, which would be parsed as an option). The special marker is removed in parsing phase.
*/
expandOptionEqualsNotation () {
const optEquals = option.optEquals
if (this.some(optEquals.test.bind(optEquals))) {
const expandedArgs = []
this.forEach(arg => {
const matches = arg.match(optEquals)
if (matches) {
expandedArgs.push(matches[1], option.VALUE_MARKER + matches[2])
} else {
expandedArgs.push(arg)
}
})
this.clear()
this.load(expandedArgs)
}
}
/**
* expand getopt-style combined options
*/
expandGetoptNotation () {
const findReplace = require('find-replace')
const combinedArg = option.combined
const hasGetopt = this.some(combinedArg.test.bind(combinedArg))
if (hasGetopt) {
findReplace(this, combinedArg, arg => {
arg = arg.slice(1)
return arg.split('').map(letter => '-' + letter)
})
}
}
/**
* Inspect the user-supplied options for validation issues.
* @throws `UNKNOWN_OPTION`
*/
validate (definitions, options) {
options = options || {}
let invalidOption
if (!options.partial) {
const optionWithoutDefinition = this
.filter(arg => option.isOption(arg))
.some(arg => {
if (definitions.get(arg) === undefined) {
invalidOption = arg
return true
}
})
if (optionWithoutDefinition) {
halt(
'UNKNOWN_OPTION',
'Unknown option: ' + invalidOption
)
}
}
}
}
function halt (name, message) {
const err = new Error(message)
err.name = name
throw err
}
module.exports = Argv

View File

@ -0,0 +1,58 @@
'use strict'
/**
* @module command-line-args
*/
module.exports = commandLineArgs
/**
* Returns an object containing all options set on the command line. By default it parses the global [`process.argv`](https://nodejs.org/api/process.html#process_process_argv) array.
*
* By default, an exception is thrown if the user sets an unknown option (one without a valid [definition](#exp_module_definition--OptionDefinition)). To enable __partial parsing__, invoke `commandLineArgs` with the `partial` option - all unknown arguments will be returned in the `_unknown` property.
*
*
* @param {module:definition[]} - An array of [OptionDefinition](#exp_module_definition--OptionDefinition) objects
* @param [options] {object} - Options.
* @param [options.argv] {string[]} - An array of strings, which if passed will be parsed instead of `process.argv`.
* @param [options.partial] {boolean} - If `true`, an array of unknown arguments is returned in the `_unknown` property of the output.
* @returns {object}
* @throws `UNKNOWN_OPTION` if `options.partial` is false and the user set an undefined option
* @throws `NAME_MISSING` if an option definition is missing the required `name` property
* @throws `INVALID_TYPE` if an option definition has a `type` value that's not a function
* @throws `INVALID_ALIAS` if an alias is numeric, a hyphen or a length other than 1
* @throws `DUPLICATE_NAME` if an option definition name was used more than once
* @throws `DUPLICATE_ALIAS` if an option definition alias was used more than once
* @throws `DUPLICATE_DEFAULT_OPTION` if more than one option definition has `defaultOption: true`
* @alias module:command-line-args
*/
function commandLineArgs (optionDefinitions, options) {
options = options || {}
const Definitions = require('./definitions')
const Argv = require('./argv')
const definitions = new Definitions()
definitions.load(optionDefinitions)
const argv = new Argv()
argv.load(options.argv)
argv.expandOptionEqualsNotation()
argv.expandGetoptNotation()
argv.validate(definitions, options)
const OutputClass = definitions.isGrouped() ? require('./grouped-output') : require('./output')
const output = new OutputClass(definitions, options)
let optionName
const option = require('./option')
for (const arg of argv) {
if (option.isOption(arg)) {
optionName = output.setFlag(arg) ? undefined : arg
} else {
if (optionName) {
optionName = output.setOptionValue(optionName, arg) ? undefined : optionName
} else {
optionName = output.setValue(arg) ? undefined : optionName
}
}
}
return output.toObject()
}

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

@ -0,0 +1,236 @@
'use strict'
const t = require('typical')
/**
* @module definition
*/
/**
* Describes a command-line option. Additionally, you can add `description` and `typeLabel` properties and make use of [command-line-usage](https://github.com/75lb/command-line-usage).
* @alias module:definition
* @typicalname option
*/
class OptionDefinition {
constructor (definition) {
/**
* The only required definition property is `name`, so the simplest working example is
* ```js
* [
* { name: "file" },
* { name: "verbose" },
* { name: "depth"}
* ]
* ```
*
* In this case, the value of each option will be either a Boolean or string.
*
* | # | Command line args | .parse() output |
* | --- | -------------------- | ------------ |
* | 1 | `--file` | `{ file: true }` |
* | 2 | `--file lib.js --verbose` | `{ file: "lib.js", verbose: true }` |
* | 3 | `--verbose very` | `{ verbose: "very" }` |
* | 4 | `--depth 2` | `{ depth: "2" }` |
*
* Unicode option names and aliases are valid, for example:
* ```js
* [
* { 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.
*
* You can use a class, if you like:
*
* ```js
* const fs = require('fs')
*
* function FileDetails(filename){
* if (!(this instanceof FileDetails)) return new FileDetails(filename)
* this.filename = filename
* this.exists = fs.existsSync(filename)
* }
*
* const cli = commandLineArgs([
* { name: 'file', type: FileDetails },
* { 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 hypen.
*
* ```js
* [
* { 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
* [
* { name: "files", type: String, multiple: true }
* ]
* ```
*
* | # | 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
/**
* Any unclaimed command-line args will be set on this option. This flag is typically set on the most commonly-used option to make for more concise usage (i.e. `$ myapp *.js` instead of `$ myapp --files *.js`).
*
* ```js
* [
* { name: "files", type: String, 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
* [
* { name: "files", type: String, 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
* [
* { 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 (value) {
return this.type === Boolean || (t.isFunction(this.type) && this.type.name === 'Boolean')
}
}
module.exports = OptionDefinition

155
node_modules/command-line-args/lib/definitions.js generated vendored Normal file
View File

@ -0,0 +1,155 @@
'use strict'
const arrayify = require('array-back')
const option = require('./option')
const Definition = require('./definition')
const t = require('typical')
/**
* @module definitions
* @private
*/
/**
* @alias module:definitions
*/
class Definitions extends Array {
load (definitions) {
this.clear()
arrayify(definitions).forEach(def => this.push(new Definition(def)))
this.validate()
}
clear () {
this.length = 0
}
/**
* validate option definitions
* @returns {string}
*/
validate (argv) {
const someHaveNoName = this.some(def => !def.name)
if (someHaveNoName) {
halt(
'NAME_MISSING',
'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_TYPE',
'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_ALIAS',
'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_ALIAS',
'Invalid option definition: an alias must be a single character'
)
}
const hypenAlias = this.some(def => {
invalidOption = def
return def.alias === '-'
})
if (hypenAlias) {
halt(
'INVALID_ALIAS',
'Invalid option definition: an alias cannot be "-"'
)
}
const duplicateName = hasDuplicates(this.map(def => def.name))
if (duplicateName) {
halt(
'DUPLICATE_NAME',
'Two or more option definitions have the same name'
)
}
const duplicateAlias = hasDuplicates(this.map(def => def.alias))
if (duplicateAlias) {
halt(
'DUPLICATE_ALIAS',
'Two or more option definitions have the same alias'
)
}
const duplicateDefaultOption = hasDuplicates(this.map(def => def.defaultOption))
if (duplicateDefaultOption) {
halt(
'DUPLICATE_DEFAULT_OPTION',
'Only one option definition can be the defaultOption'
)
}
}
/**
* @param {string}
* @returns {Definition}
*/
get (arg) {
return option.short.test(arg)
? this.find(def => def.alias === option.short.name(arg))
: this.find(def => def.name === option.long.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))
}
}
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

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

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

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

@ -0,0 +1,14 @@
'use strict'
class ArgRegExp extends RegExp {
name (arg) {
return arg.match(this)[1]
}
}
exports.short = new ArgRegExp('^-([^\\d-])$')
exports.long = new ArgRegExp('^--(\\S+)')
exports.combined = new ArgRegExp('^-([^\\d-]{2,})$')
exports.isOption = arg => exports.short.test(arg) || exports.long.test(arg)
exports.optEquals = new ArgRegExp('^(--\\S+?)=(.*)')
exports.VALUE_MARKER = '552f3a31-14cd-4ced-bd67-656a659e9efb' // must be unique

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

@ -0,0 +1,152 @@
'use strict'
const t = require('typical')
const arrayify = require('array-back')
class OutputValue {
constructor (value) {
this.value = value
this.hasDefaultArrayValue = false
this.valueSource = 'unknown'
}
isDefined () {
return t.isDefined(this.value)
}
}
class Output {
constructor (definitions, options) {
this.options = options || {}
this.output = {}
this.unknown = []
this.definitions = definitions
this._assignDefaultValues()
}
_assignDefaultValues () {
this.definitions.forEach(def => {
if (t.isDefined(def.defaultValue)) {
if (def.multiple) {
this.output[def.name] = new OutputValue(arrayify(def.defaultValue))
this.output[def.name].hasDefaultArrayValue = true
} else {
this.output[def.name] = new OutputValue(def.defaultValue)
}
this.output[def.name].valueSource = 'default'
}
})
}
setFlag (optionArg) {
const def = this.definitions.get(optionArg)
if (def) {
this.output[def.name] = this.output[def.name] || new OutputValue()
const outputValue = this.output[def.name]
if (def.multiple) outputValue.value = outputValue.value || []
/* for boolean types, set value to `true`. For all other types run value through setter function. */
if (def.isBoolean()) {
if (Array.isArray(outputValue.value)) {
outputValue.value.push(true)
} else {
outputValue.value = true
}
return true
} else {
if (!Array.isArray(outputValue.value) && outputValue.valueSource === 'unknown') outputValue.value = null
return false
}
} else {
this.unknown.push(optionArg)
return true
}
}
setOptionValue (optionArg, value) {
const ValueArg = require('./value-arg')
const valueArg = new ValueArg(value)
const def = this.definitions.get(optionArg)
this.output[def.name] = this.output[def.name] || new OutputValue()
const outputValue = this.output[def.name]
if (def.multiple) outputValue.value = outputValue.value || []
/* run value through setter function. */
valueArg.value = def.type(valueArg.value)
outputValue.valueSource = 'argv'
if (Array.isArray(outputValue.value)) {
if (outputValue.hasDefaultArrayValue) {
outputValue.value = [ valueArg.value ]
outputValue.hasDefaultArrayValue = false
} else {
outputValue.value.push(valueArg.value)
}
return false
} else {
outputValue.value = valueArg.value
return true
}
}
/**
* Return `true` when an option value was set and is not a multiple. Return `false` if option was a multiple or if a value was not yet set.
*/
setValue (value) {
const ValueArg = require('./value-arg')
const valueArg = new ValueArg(value)
/* use the defaultOption */
const def = this.definitions.getDefault()
/* handle unknown values in the case a value was already set on a defaultOption */
if (def) {
const currentValue = this.output[def.name]
if (valueArg.isDefined() && currentValue && t.isDefined(currentValue.value)) {
if (def.multiple) {
/* in the case we're setting an --option=value value on a multiple defaultOption, tag the value onto the previous unknown */
if (valueArg.isOptionValueNotationValue && this.unknown.length) {
this.unknown[this.unknown.length - 1] += `=${valueArg.value}`
return true
}
} else {
/* currentValue has already been set by argv,log this value as unknown and move on */
if (currentValue.valueSource === 'argv') {
this.unknown.push(valueArg.value)
return true
}
}
}
return this.setOptionValue(`--${def.name}`, value)
} else {
if (valueArg.isOptionValueNotationValue) {
this.unknown[this.unknown.length - 1] += `=${valueArg.value}`
} else {
this.unknown.push(valueArg.value)
}
return true
}
}
get (name) {
return this.output[name] && this.output[name].value
}
toObject () {
let output = Object.assign({}, this.output)
if (this.options.partial && this.unknown.length) {
output._unknown = this.unknown
}
for (const prop in output) {
if (prop !== '_unknown') {
output[prop] = output[prop].value
}
}
return output
}
}
module.exports = Output

36
node_modules/command-line-args/lib/output2.js generated vendored Normal file
View File

@ -0,0 +1,36 @@
class FlagOption {}
class SingleValueOption {
constructor (definition) {
this.definition = definition
}
set value (val) {
this._val = this.definition.type(val)
}
get value () {
return this._val
}
}
class MultipleValueOption {}
class Output extends Map {
constructor (definitions) {
this.definitions = definitions
}
set (key, value) {
const def = this.definitions.get(key)
}
}
const optionDefinitions = [
{ name: 'one' }
]
const output = new Output(optionDefinitions)
output.set('one', 'something')
console.log(output)
output.set('one', 'something2')
console.log(output)

18
node_modules/command-line-args/lib/value-arg.js generated vendored Normal file
View File

@ -0,0 +1,18 @@
'use strict'
const t = require('typical')
const option = require('./option')
const reBeginsWithValueMarker = new RegExp('^' + option.VALUE_MARKER)
class ValueArg {
constructor (value) {
this.isOptionValueNotationValue = reBeginsWithValueMarker.test(value)
/* if the value marker is present at the value beginning, strip it */
this.value = value ? value.replace(reBeginsWithValueMarker, '') : value
}
isDefined () {
return t.isDefined(this.value)
}
}
module.exports = ValueArg

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

@ -0,0 +1,75 @@
{
"_from": "command-line-args@^4.0.7",
"_id": "command-line-args@4.0.7",
"_inBundle": false,
"_integrity": "sha512-aUdPvQRAyBvQd2n7jXcsMDz68ckBJELXNzBybCHOibUWEg0mWTnaYCSRU8h9R+aNRSvDihJtssSRCiDRpLaezA==",
"_location": "/command-line-args",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "command-line-args@^4.0.7",
"name": "command-line-args",
"escapedName": "command-line-args",
"rawSpec": "^4.0.7",
"saveSpec": null,
"fetchSpec": "^4.0.7"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-4.0.7.tgz",
"_shasum": "f8d1916ecb90e9e121eda6428e41300bfb64cc46",
"_spec": "command-line-args@^4.0.7",
"_where": "/home/wn/workspace-node/homepage",
"author": {
"name": "Lloyd Brookes",
"email": "75pound@gmail.com"
},
"bin": {
"command-line-args": "bin/cli.js"
},
"bugs": {
"url": "https://github.com/75lb/command-line-args/issues"
},
"bundleDependencies": false,
"dependencies": {
"array-back": "^2.0.0",
"find-replace": "^1.0.3",
"typical": "^2.6.1"
},
"deprecated": false,
"description": "A mature, feature-complete library to parse command-line options.",
"devDependencies": {
"coveralls": "^2.13.1",
"jsdoc-to-markdown": "^3.0.0",
"test-runner": "^0.4.1"
},
"homepage": "https://github.com/75lb/command-line-args#readme",
"keywords": [
"argv",
"parse",
"argument",
"args",
"option",
"options",
"parser",
"parsing",
"cli",
"command",
"line"
],
"license": "MIT",
"main": "lib/command-line-args.js",
"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 && cat coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf coverage; echo",
"docs": "jsdoc2md -l off -t jsdoc2md/README.hbs lib/*.js > README.md; echo",
"test": "test-runner test/*.js"
},
"version": "4.0.7"
}

35
node_modules/command-line-args/test/alias.js generated vendored Normal file
View File

@ -0,0 +1,35 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const runner = new TestRunner()
const optionDefinitions = [
{ name: 'verbose', alias: 'v' },
{ name: 'colour', alias: 'c' },
{ name: 'number', alias: 'n' },
{ name: 'dry-run', alias: 'd' }
]
runner.test('alias: one boolean', function () {
const argv = [ '-v' ]
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
verbose: null
})
})
runner.test('alias: one --this-type boolean', function () {
const argv = [ '-d' ]
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
'dry-run': null
})
})
runner.test('alias: one boolean, one string', function () {
const argv = [ '-v', '-c' ]
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
verbose: null,
colour: null
})
})

24
node_modules/command-line-args/test/ambiguous-input.js generated vendored Normal file
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('ambiguous input: value looks like option', function () {
const optionDefinitions = [
{ name: 'colour', type: String, alias: 'c' }
]
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv: [ '-c', 'red' ] }), {
colour: 'red'
})
a.throws(function () {
commandLineArgs(optionDefinitions, { argv: [ '--colour', '--red' ] })
})
a.doesNotThrow(function () {
commandLineArgs(optionDefinitions, { argv: [ '--colour=--red' ] })
})
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv: [ '--colour=--red' ] }), {
colour: '--red'
})
})

57
node_modules/command-line-args/test/bad-input.js generated vendored Normal file
View File

@ -0,0 +1,57 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const runner = new TestRunner()
runner.test('bad-input: handles missing option value', function () {
const definitions = [
{ name: 'colour', type: String },
{ name: 'files' }
]
a.deepStrictEqual(commandLineArgs(definitions, { argv: [ '--colour' ] }), {
colour: null
})
a.deepStrictEqual(commandLineArgs(definitions, { argv: [ '--colour', '--files', 'yeah' ] }), {
colour: null,
files: 'yeah'
})
})
runner.test('bad-input: handles arrays with relative paths', function () {
const definitions = [
{ name: 'colours', type: String, multiple: true }
]
const argv = [ '--colours', '../what', '../ever' ]
a.deepStrictEqual(commandLineArgs(definitions, { argv }), {
colours: [ '../what', '../ever' ]
})
})
runner.test('bad-input: empty string', function () {
const definitions = [
{ name: 'one', type: String },
{ name: 'two', type: Number },
{ name: 'three', type: Number, multiple: true },
{ name: 'four', type: String },
{ name: 'five', type: Boolean }
]
const argv = [ '--one', '', '', '--two', '0', '--three=', '', '--four=', '--five=' ]
a.deepStrictEqual(commandLineArgs(definitions, { argv }), {
one: '',
two: 0,
three: [ 0, 0 ],
four: '',
five: true
})
})
runner.test('bad-input: non-strings in argv', function () {
const definitions = [
{ name: 'one', type: Number }
]
const argv = [ '--one', 1 ]
const result = commandLineArgs(definitions, { argv })
a.deepStrictEqual(result, { one: 1 })
})

72
node_modules/command-line-args/test/class-argv.js generated vendored Normal file
View File

@ -0,0 +1,72 @@
'use strict'
const TestRunner = require('test-runner')
const a = require('assert')
const Argv = require('../lib/argv')
const Definitions = require('../lib/definitions')
const runner = new TestRunner()
runner.test('.expandOptionEqualsNotation()', function () {
const argv = new Argv()
argv.load([ '--one=1', '--two', '2', '--three=3', '4' ])
argv.expandOptionEqualsNotation()
a.deepEqual(argv, [
'--one', '552f3a31-14cd-4ced-bd67-656a659e9efb1', '--two', '2', '--three', '552f3a31-14cd-4ced-bd67-656a659e9efb3', '4'
])
})
runner.test('.expandGetoptNotation()', function () {
const argv = new Argv()
argv.load([ '-abc' ])
argv.expandGetoptNotation()
a.deepEqual(argv.slice(), [
'-a', '-b', '-c'
])
})
runner.test('.expandGetoptNotation() with values', function () {
const argv = new Argv()
argv.load([ '-abc', '1', '-a', '2', '-bc' ])
argv.expandGetoptNotation()
a.deepEqual(argv, [
'-a', '-b', '-c', '1', '-a', '2', '-b', '-c'
])
})
runner.test('.validate()', function () {
const definitions = new Definitions()
definitions.load([
{ name: 'one', type: Number }
])
a.doesNotThrow(function () {
const argv = new Argv()
argv.load([ '--one', '1' ])
argv.validate(definitions)
})
a.throws(function () {
const argv = new Argv()
argv.load([ '--one', '--two' ])
argv.validate(definitions)
})
a.throws(function () {
const argv = new Argv()
argv.load([ '--one', '2', '--two', 'two' ])
argv.validate(definitions)
})
a.throws(function () {
const argv = new Argv()
argv.load([ '-a', '2' ])
argv.validate(definitions)
})
})
runner.test('expandOptionEqualsNotation', function () {
const argv = new Argv()
argv.load([ '--one=tree' ])
argv.expandOptionEqualsNotation()
a.deepEqual(argv, [ '--one', '552f3a31-14cd-4ced-bd67-656a659e9efbtree' ])
})

View File

@ -0,0 +1,19 @@
'use strict'
const TestRunner = require('test-runner')
const a = require('assert')
const Definitions = require('../lib/definitions')
const runner = new TestRunner()
runner.test('.get()', function () {
const definitions = new Definitions()
definitions.load([ { name: 'one', defaultValue: 'eins' } ])
a.strictEqual(definitions.get('--one').name, 'one')
})
runner.test('.validate()', function () {
a.throws(function () {
const definitions = new Definitions()
definitions.load([ { name: 'one' }, { name: 'one' } ])
})
})

98
node_modules/command-line-args/test/class-output.js generated vendored Normal file
View File

@ -0,0 +1,98 @@
'use strict'
const TestRunner = require('test-runner')
const a = require('assert')
const Output = require('../lib/output')
const Definitions = require('../lib/definitions')
const runner = new TestRunner()
runner.test('output.setFlag(name): initial value', function () {
let definitions = new Definitions()
definitions.load([
{ name: 'one', type: Number }
])
let output = new Output(definitions)
a.strictEqual(output.get('one'), undefined)
output.setFlag('--one')
a.strictEqual(output.get('one'), null)
definitions.load([
{ name: 'one', type: Boolean }
])
output = new Output(definitions)
a.strictEqual(output.get('one'), undefined)
output.setFlag('--one')
a.strictEqual(output.get('one'), true)
})
runner.test('output.setOptionValue(name, value)', function () {
const definitions = new Definitions()
definitions.load([
{ name: 'one', type: Number, defaultValue: 1 }
])
const output = new Output(definitions)
a.strictEqual(output.get('one'), 1)
output.setOptionValue('--one', '2')
a.strictEqual(output.get('one'), 2)
})
runner.test('output.setOptionValue(name, value): multiple, defaultValue', function () {
const definitions = new Definitions()
definitions.load([
{ name: 'one', type: Number, multiple: true, defaultValue: [ 1 ] }
])
const output = new Output(definitions)
a.deepStrictEqual(output.get('one'), [ 1 ])
output.setOptionValue('--one', '2')
a.deepStrictEqual(output.get('one'), [ 2 ])
})
runner.test('output.setOptionValue(name, value): multiple 2', function () {
const definitions = new Definitions()
definitions.load([
{ name: 'one', type: Number, multiple: true }
])
const output = new Output(definitions)
a.deepStrictEqual(output.get('one'), undefined)
output.setOptionValue('--one', '2')
a.deepStrictEqual(output.get('one'), [ 2 ])
output.setOptionValue('--one', '3')
a.deepStrictEqual(output.get('one'), [ 2, 3 ])
})
runner.test('output.setValue(value): no defaultOption', function () {
const definitions = new Definitions()
definitions.load([
{ name: 'one', type: Number }
])
const output = new Output(definitions)
a.deepStrictEqual(output.get('one'), undefined)
output.setValue('2')
a.deepStrictEqual(output.get('one'), undefined)
a.deepStrictEqual(output.unknown, [ '2' ])
})
runner.test('output.setValue(value): with defaultOption', function () {
const definitions = new Definitions()
definitions.load([
{ name: 'one', type: Number, defaultOption: true }
])
const output = new Output(definitions)
a.deepStrictEqual(output.get('one'), undefined)
output.setValue('2')
a.deepStrictEqual(output.get('one'), 2)
a.deepStrictEqual(output.unknown, [])
})
runner.test('output.setValue(value): multiple', function () {
const definitions = new Definitions()
definitions.load([
{ name: 'one', multiple: true, defaultOption: true }
])
const output = new Output(definitions)
a.deepStrictEqual(output.get('one'), undefined)
output.setValue('1')
a.deepStrictEqual(output.get('one'), [ '1' ])
output.setValue('2')
a.deepStrictEqual(output.get('one'), [ '1', '2' ])
})

99
node_modules/command-line-args/test/default-option.js generated vendored Normal file
View File

@ -0,0 +1,99 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const runner = new TestRunner()
runner.test('defaultOption: string', function () {
const optionDefinitions = [
{ name: 'files', defaultOption: true }
]
const argv = [ 'file1', 'file2' ]
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
files: 'file1'
})
})
runner.test('defaultOption: multiple string', function () {
const optionDefinitions = [
{ name: 'files', defaultOption: true, multiple: true }
]
const argv = [ 'file1', 'file2' ]
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
files: [ 'file1', 'file2' ]
})
})
runner.test('defaultOption: after a boolean', function () {
const definitions = [
{ name: 'one', type: Boolean },
{ name: 'two', defaultOption: true }
]
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one', 'sfsgf' ] }),
{ one: true, two: 'sfsgf' }
)
})
runner.test('defaultOption: multiple defaultOption values between other arg/value pairs', function () {
const optionDefinitions = [
{ name: 'one' },
{ name: 'two' },
{ name: 'files', defaultOption: true, multiple: true }
]
const argv = [ '--one', '1', 'file1', 'file2', '--two', '2' ]
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
one: '1',
two: '2',
files: [ 'file1', 'file2' ]
})
})
runner.test('defaultOption: multiple defaultOption values between other arg/value pairs 2', function () {
const optionDefinitions = [
{ name: 'one', type: Boolean },
{ name: 'two' },
{ name: 'files', defaultOption: true, multiple: true }
]
const argv = [ 'file0', '--one', 'file1', '--files', 'file2', '--two', '2', 'file3' ]
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
one: true,
two: '2',
files: [ 'file0', 'file1', 'file2', 'file3' ]
})
})
runner.test('defaultOption: floating args present but no defaultOption', function () {
const definitions = [
{ name: 'one', type: Boolean }
]
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ 'aaa', '--one', 'aaa', 'aaa' ] }),
{ one: true }
)
})
runner.test('defaultOption: non-multiple should take first value', function () {
const optionDefinitions = [
{ name: 'file', defaultOption: true }
]
const argv = [ 'file1', 'file2' ]
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
file: 'file1'
})
})
runner.test('defaultOption: non-multiple should take first value 2', function () {
const optionDefinitions = [
{ name: 'file', defaultOption: true },
{ name: 'one', type: Boolean },
{ name: 'two', type: Boolean }
]
const argv = [ '--two', 'file1', '--one', 'file2' ]
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
file: 'file1',
two: true,
one: true
})
})

145
node_modules/command-line-args/test/default-value.js generated vendored Normal file
View File

@ -0,0 +1,145 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const runner = new TestRunner()
runner.test('default value', function () {
let defs = [
{ name: 'one' },
{ name: 'two', defaultValue: 'two' }
]
let argv = [ '--one', '1' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
one: '1',
two: 'two'
})
defs = [ { name: 'two', defaultValue: 'two' } ]
argv = []
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: 'two' })
defs = [ { name: 'two', defaultValue: 'two' } ]
argv = [ '--two', 'zwei' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: 'zwei' })
defs = [ { name: 'two', multiple: true, defaultValue: [ 'two', 'zwei' ] } ]
argv = [ '--two', 'duo' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: [ 'duo' ] })
})
runner.test('default value 2', function () {
const defs = [{ name: 'two', multiple: true, defaultValue: ['two', 'zwei'] }]
const result = commandLineArgs(defs, [])
a.deepStrictEqual(result, { two: [ 'two', 'zwei' ] })
})
runner.test('default value: array as defaultOption', function () {
const defs = [
{ name: 'two', multiple: true, defaultValue: ['two', 'zwei'], defaultOption: true }
]
const argv = [ 'duo' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: [ 'duo' ] })
})
runner.test('default value: falsy default values', function () {
const defs = [
{ name: 'one', defaultValue: 0 },
{ name: 'two', defaultValue: false }
]
const argv = []
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
one: 0,
two: false
})
})
runner.test('default value: is arrayifed if multiple set', function () {
const defs = [
{ name: 'one', defaultValue: 0, multiple: true }
]
let argv = []
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
one: [ 0 ]
})
argv = [ '--one', '2' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
one: [ '2' ]
})
})
runner.test('default value: combined with defaultOption', function () {
const defs = [
{ name: 'path', defaultOption: true, defaultValue: './' }
]
let argv = [ '--path', 'test' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: 'test'
})
argv = [ 'test' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: 'test'
})
argv = [ ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: './'
})
})
runner.test('default value: combined with multiple and defaultOption', function () {
const defs = [
{ name: 'path', multiple: true, defaultOption: true, defaultValue: './' }
]
let argv = [ '--path', 'test1', 'test2' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: [ 'test1', 'test2' ]
})
argv = [ '--path', 'test' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: [ 'test' ]
})
argv = [ 'test1', 'test2' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: [ 'test1', 'test2' ]
})
argv = [ 'test' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: [ 'test' ]
})
argv = [ ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: [ './' ]
})
})
runner.test('default value: array default combined with multiple and defaultOption', function () {
const defs = [
{ name: 'path', multiple: true, defaultOption: true, defaultValue: [ './' ] }
]
let argv = [ '--path', 'test1', 'test2' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: [ 'test1', 'test2' ]
})
argv = [ '--path', 'test' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: [ 'test' ]
})
argv = [ 'test1', 'test2' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: [ 'test1', 'test2' ]
})
argv = [ 'test' ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: [ 'test' ]
})
argv = [ ]
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
path: [ './' ]
})
})

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('detect process.argv: should automatically remove first two argv items', function () {
process.argv = [ 'node', 'filename', '--one', 'eins' ]
a.deepStrictEqual(commandLineArgs({ name: 'one' }, { argv: process.argv }), {
one: 'eins'
})
})
runner.test('process.argv is left untouched', function () {
process.argv = [ 'node', 'filename', '--one', 'eins' ]
a.deepStrictEqual(commandLineArgs({ name: 'one' }), {
one: 'eins'
})
a.deepStrictEqual(process.argv, [ 'node', 'filename', '--one', 'eins' ])
})

176
node_modules/command-line-args/test/exceptions.js generated vendored Normal file
View File

@ -0,0 +1,176 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const runner = new TestRunner()
runner.test('err-invalid-definition: throws when no definition.name specified', function () {
const optionDefinitions = [
{ something: 'one' },
{ something: 'two' }
]
const argv = [ '--one', '--two' ]
try {
commandLineArgs(optionDefinitions, { argv })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'NAME_MISSING')
}
})
runner.test('err-invalid-definition: throws if dev set a numeric alias', function () {
const optionDefinitions = [
{ name: 'colours', alias: '1' }
]
const argv = [ '--colours', 'red' ]
try {
commandLineArgs(optionDefinitions, { argv })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'INVALID_ALIAS')
}
})
runner.test('err-invalid-definition: throws if dev set an alias of "-"', function () {
const optionDefinitions = [
{ name: 'colours', alias: '-' }
]
const argv = [ '--colours', 'red' ]
try {
commandLineArgs(optionDefinitions, { argv })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'INVALID_ALIAS')
}
})
runner.test('err-invalid-definition: multi-character alias', function () {
const optionDefinitions = [
{ name: 'one', alias: 'aa' }
]
const argv = [ '--one', 'red' ]
try {
commandLineArgs(optionDefinitions, { argv })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'INVALID_ALIAS')
}
})
runner.test('err-invalid-definition: invalid type values', function () {
const argv = [ '--one', 'something' ]
try {
commandLineArgs([ { name: 'one', type: 'string' } ], { argv })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'INVALID_TYPE')
}
try {
commandLineArgs([ { name: 'one', type: 234 } ], { argv })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'INVALID_TYPE')
}
try {
commandLineArgs([ { name: 'one', type: {} } ], { argv })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'INVALID_TYPE')
}
a.doesNotThrow(function () {
commandLineArgs([ { name: 'one', type: function () {} } ], { argv })
}, /invalid/i)
})
runner.test('err-invalid-definition: value without option definition', function () {
const optionDefinitions = [
{ name: 'one', type: Number }
]
a.deepStrictEqual(
commandLineArgs(optionDefinitions, { argv: [ '--one', '1' ] }),
{ one: 1 }
)
try {
commandLineArgs(optionDefinitions, { argv: [ '--one', '--two' ] })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'UNKNOWN_OPTION')
}
try {
commandLineArgs(optionDefinitions, { argv: [ '--one', '2', '--two', 'two' ] })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'UNKNOWN_OPTION')
}
try {
commandLineArgs(optionDefinitions, { argv: [ '-a', '2' ] })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'UNKNOWN_OPTION')
}
try {
commandLineArgs(optionDefinitions, { argv: [ '-sdf' ] })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'UNKNOWN_OPTION', 'getOpts')
}
})
runner.test('err-invalid-definition: duplicate name', function () {
const optionDefinitions = [
{ name: 'colours' },
{ name: 'colours' }
]
const argv = [ '--colours', 'red' ]
try {
commandLineArgs(optionDefinitions, { argv })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'DUPLICATE_NAME')
}
})
runner.test('err-invalid-definition: duplicate alias', function () {
const optionDefinitions = [
{ name: 'one', alias: 'a' },
{ name: 'two', alias: 'a' }
]
const argv = [ '--one', 'red' ]
try {
commandLineArgs(optionDefinitions, { argv })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'DUPLICATE_ALIAS')
}
})
runner.test('err-invalid-definition: multiple defaultOption', function () {
const optionDefinitions = [
{ name: 'one', defaultOption: true },
{ name: 'two', defaultOption: true }
]
const argv = [ '--one', 'red' ]
try {
commandLineArgs(optionDefinitions, { argv })
a.fail()
} catch (err) {
a.strictEqual(err.name, 'DUPLICATE_DEFAULT_OPTION')
}
})
runner.test('err-invalid-defaultOption: defaultOption on a Boolean type')

120
node_modules/command-line-args/test/grouping.js generated vendored Normal file
View File

@ -0,0 +1,120 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const runner = new TestRunner()
runner.test('groups', function () {
const definitions = [
{ name: 'one', group: 'a' },
{ name: 'two', group: 'a' },
{ name: 'three', group: 'b' }
]
const argv = [ '--one', '1', '--two', '2', '--three', '3' ]
const output = commandLineArgs(definitions, { argv })
a.deepStrictEqual(output, {
a: {
one: '1',
two: '2'
},
b: {
three: '3'
},
_all: {
one: '1',
two: '2',
three: '3'
}
})
})
runner.test('groups: multiple and _none', function () {
const definitions = [
{ name: 'one', group: ['a', 'f'] },
{ name: 'two', group: ['a', 'g'] },
{ name: 'three' }
]
a.deepStrictEqual(commandLineArgs(definitions, { argv: [ '--one', '1', '--two', '2', '--three', '3' ] }), {
a: {
one: '1',
two: '2'
},
f: {
one: '1'
},
g: {
two: '2'
},
_none: {
three: '3'
},
_all: {
one: '1',
two: '2',
three: '3'
}
})
})
runner.test('groups: nothing set', function () {
const definitions = [
{ name: 'one', group: 'a' },
{ name: 'two', group: 'a' },
{ name: 'three', group: 'b' }
]
const argv = [ ]
const output = commandLineArgs(definitions, { argv })
a.deepStrictEqual(output, {
a: {},
b: {},
_all: {}
})
})
runner.test('groups: nothing set with one ungrouped', function () {
const definitions = [
{ name: 'one', group: 'a' },
{ name: 'two', group: 'a' },
{ name: 'three' }
]
const argv = [ ]
const output = commandLineArgs(definitions, { argv })
a.deepStrictEqual(output, {
a: {},
_all: {}
})
})
runner.test('groups: two ungrouped, one set', function () {
const definitions = [
{ name: 'one', group: 'a' },
{ name: 'two', group: 'a' },
{ name: 'three' },
{ name: 'four' }
]
const argv = [ '--three', '3' ]
const output = commandLineArgs(definitions, { argv })
a.deepStrictEqual(output, {
a: {},
_all: { three: '3' },
_none: { three: '3' }
})
})
runner.test('groups: two ungrouped, both set', function () {
const definitions = [
{ name: 'one', group: 'a' },
{ name: 'two', group: 'a' },
{ name: 'three' },
{ name: 'four' }
]
const argv = [ '--three', '3', '--four', '4' ]
const output = commandLineArgs(definitions, { argv })
a.deepStrictEqual(output, {
a: {},
_all: { three: '3', four: '4' },
_none: { three: '3', four: '4' }
})
})

33
node_modules/command-line-args/test/multiple.js generated vendored Normal file
View File

@ -0,0 +1,33 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const runner = new TestRunner()
runner.test('multiple: string unset', function () {
const argv = []
const optionDefinitions = [
{ name: 'one', multiple: true }
]
const result = commandLineArgs(optionDefinitions, { argv })
a.deepStrictEqual(result, { })
})
runner.test('multiple: string unset with defaultValue', function () {
const argv = []
const optionDefinitions = [
{ name: 'one', multiple: true, defaultValue: 1 }
]
const result = commandLineArgs(optionDefinitions, { argv })
a.deepStrictEqual(result, { one: [ 1 ]})
})
runner.test('multiple: boolean unset', function () {
const argv = []
const optionDefinitions = [
{ name: 'one', type: Boolean, multiple: true }
]
const result = commandLineArgs(optionDefinitions, { argv })
a.deepStrictEqual(result, { })
})

22
node_modules/command-line-args/test/name-alias-mix.js generated vendored Normal file
View File

@ -0,0 +1,22 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const runner = new TestRunner()
const optionDefinitions = [
{ name: 'one', alias: 'o' },
{ name: 'two', alias: 't' },
{ name: 'three', alias: 'h' },
{ name: 'four', alias: 'f' }
]
runner.test('name-alias-mix: one of each', function () {
const argv = [ '--one', '-t', '--three' ]
const result = commandLineArgs(optionDefinitions, { argv })
a.strictEqual(result.one, null)
a.strictEqual(result.two, null)
a.strictEqual(result.three, null)
a.strictEqual(result.four, undefined)
})

20
node_modules/command-line-args/test/name-unicode.js generated vendored Normal file
View File

@ -0,0 +1,20 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const runner = new TestRunner()
const optionDefinitions = [
{ name: 'один' },
{ name: '两' },
{ name: 'три', alias: 'т' }
]
runner.test('name-unicode: unicode names and aliases are permitted', function () {
const argv = [ '--один', '1', '--两', '2', '-т', '3' ]
const result = commandLineArgs(optionDefinitions, { argv })
a.strictEqual(result.один, '1')
a.strictEqual(result., '2')
a.strictEqual(result.три, '3')
})

54
node_modules/command-line-args/test/notations.js generated vendored Normal file
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')
})

11
node_modules/command-line-args/test/option.js generated vendored Normal file
View File

@ -0,0 +1,11 @@
'use strict'
const TestRunner = require('test-runner')
const a = require('assert')
const option = require('../lib/option')
const runner = new TestRunner()
runner.test('option', function () {
a.strictEqual(option.isOption('--yeah'), true)
a.strictEqual(option.isOption('в--yeah'), false)
})

200
node_modules/command-line-args/test/partial.js generated vendored Normal file
View File

@ -0,0 +1,200 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const runner = new TestRunner()
runner.test('partial: simple', function () {
const definitions = [
{ name: 'one', type: Boolean }
]
const argv = [ '--two', 'two', '--one', 'two' ]
const options = commandLineArgs(definitions, { argv, partial: true })
a.deepStrictEqual(options, {
one: true,
_unknown: [ '--two', 'two', 'two' ]
})
})
runner.test('partial: defaultOption', function () {
const definitions = [
{ name: 'files', type: String, defaultOption: true, multiple: true }
]
const argv = [ '--files', 'file1', '--one', 'file2' ]
const options = commandLineArgs(definitions, { argv, partial: true })
a.deepStrictEqual(options, {
files: [ 'file1', 'file2' ],
_unknown: [ '--one' ]
})
})
runner.test('partial: defaultOption 2', function () {
const definitions = [
{ name: 'files', type: String, defaultOption: true, multiple: true },
{ name: 'one', type: Boolean },
{ name: 'two', alias: 't', defaultValue: 2 }
]
const argv = [ 'file1', '--one', 'file2', '-t', '--two=3', 'file3', '-ab' ]
const options = commandLineArgs(definitions, { argv, partial: true })
a.deepStrictEqual(options, {
files: [ 'file1', 'file2', 'file3' ],
two: '3',
one: true,
_unknown: [ '-a', '-b' ]
})
})
runner.test('partial: defaultOption with value equal to defaultValue', function () {
const definitions = [
{ name: 'file', type: String, defaultOption: true, defaultValue: 'file1' }
]
const argv = [ 'file1', '--two=3', '--four', '5' ]
const options = commandLineArgs(definitions, { argv, partial: true })
a.deepStrictEqual(options, {
file: 'file1',
_unknown: [ '--two', '3', '--four', '5' ]
})
})
runner.test('partial: defaultOption with value equal to defaultValue 2', function () {
const definitions = [
{ name: 'file', type: String, defaultOption: true, defaultValue: 'file1' }
]
const argv = [ '--file', '--file=file1', '--two=3', '--four', '5' ]
const options = commandLineArgs(definitions, { argv, partial: true })
a.deepStrictEqual(options, {
file: 'file1',
_unknown: [ '--two', '3', '--four', '5' ]
})
})
runner.test('partial: multiple', function () {
const definitions = [
{ name: 'files', type: String, multiple: true }
]
const argv = [ 'file1', '--files', 'file2', '-t', '--two=3', 'file3', '-ab', '--files=file4' ]
const options = commandLineArgs(definitions, { argv, partial: true })
a.deepStrictEqual(options, {
files: [ 'file2', 'file4' ],
_unknown: [ 'file1', '-t', '--two=3', 'file3', '-a', '-b' ]
})
})
runner.test('unknown options: rejected defaultOption values end up in _unknown', function () {
const definitions = [
{ name: 'foo', type: String },
{ name: 'verbose', alias: 'v', type: Boolean },
{ name: 'libs', type: String, defaultOption: true }
]
const argv = [ '--foo', 'bar', '-v', 'libfn', '--libarg', 'val1', '-r' ]
const options = commandLineArgs(definitions, { argv, partial: true })
a.deepStrictEqual(options, {
foo: 'bar',
verbose: true,
libs: 'libfn',
_unknown: [ '--libarg', 'val1', '-r' ]
})
})
runner.test('partial: groups', function () {
const definitions = [
{ name: 'one', group: 'a' },
{ name: 'two', group: 'a' },
{ name: 'three', group: 'b' }
]
const argv = [ '--one', '1', '--two', '2', '--three', '3', 'ham', '--cheese' ]
a.deepStrictEqual(commandLineArgs(definitions, { argv, partial: true }), {
a: {
one: '1',
two: '2'
},
b: {
three: '3'
},
_all: {
one: '1',
two: '2',
three: '3'
},
_unknown: [ 'ham', '--cheese' ]
})
})
runner.test('partial: multiple groups and _none', function () {
const definitions = [
{ name: 'one', group: ['a', 'f'] },
{ name: 'two', group: ['a', 'g'] },
{ name: 'three' }
]
const argv = [ '--cheese', '--one', '1', 'ham', '--two', '2', '--three', '3', '-c' ]
a.deepStrictEqual(commandLineArgs(definitions, { argv, partial: true }), {
a: {
one: '1',
two: '2'
},
f: {
one: '1'
},
g: {
two: '2'
},
_none: {
three: '3'
},
_all: {
one: '1',
two: '2',
three: '3'
},
_unknown: [ '--cheese', 'ham', '-c' ]
})
})
runner.test('partial: defaultOption with --option=value notation', function () {
const definitions = [
{ name: 'files', type: String, multiple: true, defaultOption: true }
]
const argv = [ 'file1', 'file2', '--unknown=something' ]
const options = commandLineArgs(definitions, { argv, partial: true })
a.deepStrictEqual(options, {
files: [ 'file1', 'file2' ],
_unknown: [ '--unknown=something' ]
})
})
runner.test('partial: defaultOption with --option=value notation 2', function () {
const definitions = [
{ name: 'files', type: String, multiple: true, defaultOption: true }
]
const argv = [ 'file1', 'file2', '--unknown=something', '--files', 'file3', '--files=file4' ]
const options = commandLineArgs(definitions, { argv, partial: true })
a.deepStrictEqual(options, {
files: [ 'file1', 'file2', 'file3', 'file4' ],
_unknown: [ '--unknown=something' ]
})
})
runner.test('partial: defaultOption with --option=value notation 3', function () {
const definitions = [
{ name: 'files', type: String, multiple: true, defaultOption: true }
]
const argv = [ '--unknown', 'file1', '--another', 'something', 'file2', '--unknown=something', '--files', 'file3', '--files=file4' ]
const options = commandLineArgs(definitions, { argv, partial: true })
a.deepStrictEqual(options, {
files: [ 'file1', 'something', 'file2', 'file3', 'file4' ],
_unknown: [ '--unknown', '--another', '--unknown=something' ]
})
})
runner.test('partial: mulitple unknowns with same name', function () {
const definitions = [
{ name: 'file' }
]
const argv = [ '--unknown', '--unknown=something', '--file=file1', '--unknown' ]
const options = commandLineArgs(definitions, { argv, partial: true })
a.deepStrictEqual(options, {
file: 'file1',
_unknown: [ '--unknown', '--unknown=something', '--unknown' ]
})
})

70
node_modules/command-line-args/test/type-boolean.js generated vendored Normal file
View File

@ -0,0 +1,70 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const runner = new TestRunner()
runner.test('type-boolean: different values', function () {
const definitions = [
{ name: 'one', type: Boolean }
]
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one' ] }),
{ one: true }
)
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one', 'true' ] }),
{ one: true }
)
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one', 'false' ] }),
{ one: true }
)
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one', 'sfsgf' ] }),
{ one: true }
)
})
const origBoolean = Boolean
/* test in contexts which override the standard global Boolean constructor */
runner.test('type-boolean: global Boolean overridden', function () {
function Boolean () {
return origBoolean.apply(origBoolean, arguments)
}
const definitions = [
{ name: 'one', type: Boolean }
]
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one', 'true' ] }),
{ one: true }
)
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one', 'false' ] }),
{ one: true }
)
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one', 'sfsgf' ] }),
{ one: true }
)
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one' ] }),
{ one: true }
)
})
runner.test('type-boolean-multiple: 1', function () {
const definitions = [
{ name: 'array', type: Boolean, multiple: true }
]
const argv = [ '--array', '--array', '--array' ]
const result = commandLineArgs(definitions, { argv })
a.deepStrictEqual(result, {
array: [ true, true, true ]
})
})

44
node_modules/command-line-args/test/type-none.js generated vendored Normal file
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: [] }
)
})

25
node_modules/command-line-args/test/type-string.js generated vendored Normal file
View File

@ -0,0 +1,25 @@
'use strict'
const TestRunner = require('test-runner')
const commandLineArgs = require('../')
const a = require('assert')
const definitions = [
{ name: 'one', type: String }
]
const runner = new TestRunner()
runner.test('type-string: different values', function () {
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one', 'yeah' ] }),
{ one: 'yeah' }
)
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one' ] }),
{ one: null }
)
a.deepStrictEqual(
commandLineArgs(definitions, { argv: [ '--one', '3' ] }),
{ one: '3' }
)
})