Socket
Socket
Sign inDemoInstall

command-line-args

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

command-line-args - npm Package Compare versions

Comparing version 2.1.3 to 2.1.4

6

es5/definition.js

@@ -12,7 +12,13 @@ 'use strict';

this.name = definition.name;
this.type = definition.type;
this.alias = definition.alias;
this.multiple = definition.multiple;
this.defaultOption = definition.defaultOption;
this.defaultValue = definition.defaultValue;
this.group = definition.group;

@@ -19,0 +25,0 @@

2

index.js
var detect = require('feature-detect-es6')
if (detect.class() && detect.arrowFunction() && detect.newArrayFeatures()) {
if (detect.all('class', 'arrowFunction', 'newArrayFeatures')) {
module.exports = require('./lib/command-line-args')

@@ -5,0 +5,0 @@ } else {

@@ -11,33 +11,35 @@ 'use strict'

/**
A library to collect command-line args and generate a usage guide.
@module command-line-args
*/
* A library to collect command-line args and generate a usage guide.
*
* @module command-line-args
*/
module.exports = commandLineArgs
/**
* @class
* @classdesc A class encapsulating operations you can perform using an [OptionDefinition](#exp_module_definition--OptionDefinition) array as input.
* A class encapsulating operations you can perform using an [OptionDefinition](#exp_module_definition--OptionDefinition) array as input.
*
* The constructor will throw if you pass invalid option definitions. You should fix these issues before proceeding.
* @param {module:definition[]} - An optional array of [OptionDefinition](#exp_module_definition--OptionDefinition) objects
* @typicalname cli
* @alias module:command-line-args
* @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`
* @example
* ```js
* var commandLineArgs = require('command-line-args')
* var cli = commandLineArgs([
* { name: 'file' },
* { name: 'verbose' },
* { name: 'depth'}
* ])
* ```
*/
class CommandLineArgs {
/**
* The constructor will throw if you pass invalid option definitions. You should fix these issues before proceeding.
*
* @param {module:definition[]} - An optional array of [OptionDefinition](#exp_module_definition--OptionDefinition) objects
* @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`
* @example
* ```js
* var commandLineArgs = require('command-line-args')
* var cli = commandLineArgs([
* { name: 'file' },
* { name: 'verbose' },
* { name: 'depth'}
* ])
* ```
*/
constructor (definitions) {

@@ -44,0 +46,0 @@ this.definitions = new Definitions(definitions)

'use strict'
/**
@module definition
*/
* @module definition
*/
/**
@class
@classdesc Describes a command-line option.
@alias module:definition
@typicalname option
*/
* Describes a command-line option. The additional properties `description` and `typeLabel` used by {@link module:command-line-args#getUsage .getUsage()} are described [here](https://github.com/75lb/command-line-usage#getusagedefinitions-options--string-).
* @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
* var fs = require('fs')
*
* function FileDetails(filename){
* if (!(this instanceof FileDetails)) return new FileDetails(filename)
* this.filename = filename
* this.exists = fs.existsSync(filename)
* }
*
* var 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}
*/
this.type = definition.type
/**
* 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

@@ -41,223 +241,4 @@

}
/* Note: as a temporary workaround of a jsdoc bug, the jsdoc comments are written below within the main block of the class rather than alongside the members */
/**
* 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}
* @member name
* @instance
*/
/**
* 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
* var fs = require('fs')
*
* function FileDetails(filename){
* if (!(this instanceof FileDetails)) return new FileDetails(filename)
* this.filename = filename
* this.exists = fs.existsSync(filename)
* }
*
* var 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}
* @member type
* @instance
*/
/**
* 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}
* @member alias
* @instance
*/
/**
* Set this flag if the option takes a list of values. You will receive an array of values 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}
* @member multiple
* @instance
*/
/**
* 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}
* @member defaultOption
* @instance
*/
/**
* 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 {*}
* @member defaultValue
* @instance
*/
/**
* 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[]}
* @member group
* @instance
*/
}
module.exports = OptionDefinition
{
"name": "command-line-args",
"version": "2.1.3",
"version": "2.1.4",
"description": "A library to collect command-line args and generate a usage guide.",

@@ -20,2 +20,3 @@ "repository": "https://github.com/75lb/command-line-args.git",

"option",
"options",
"parser",

@@ -40,4 +41,4 @@ "parsing",

"command-line-usage": "^2",
"core-js": "^1.2.1",
"feature-detect-es6": "^1",
"core-js": "^2.0.1",
"feature-detect-es6": "^1.2.0",
"find-replace": "^1",

@@ -44,0 +45,0 @@ "object-tools": "^2",

@@ -7,2 +7,3 @@ [![view on npm](http://img.shields.io/npm/v/command-line-args.svg)](https://www.npmjs.org/package/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)

@@ -108,6 +109,6 @@ # command-line-args

* [command-line-args](#module_command-line-args)
* [CommandLineArgs](#exp_module_command-line-args--CommandLineArgs) ⏏
* [new CommandLineArgs(definitions)](#new_module_command-line-args--CommandLineArgs_new)
* [.parse([argv])](#module_command-line-args--CommandLineArgs+parse) ⇒ <code>object</code>
* [.getUsage([options])](#module_command-line-args--CommandLineArgs+getUsage) ⇒ <code>string</code>
* [CommandLineArgs](#exp_module_command-line-args--CommandLineArgs) ⏏
* [new CommandLineArgs(definitions)](#new_module_command-line-args--CommandLineArgs_new)
* [.parse([argv])](#module_command-line-args--CommandLineArgs+parse) ⇒ <code>object</code>
* [.getUsage([options])](#module_command-line-args--CommandLineArgs+getUsage) ⇒ <code>string</code>

@@ -118,7 +119,7 @@ <a name="exp_module_command-line-args--CommandLineArgs"></a>

The constructor will throw if you pass invalid option definitions. You should fix these issues before proceeding.
**Kind**: Exported class
<a name="new_module_command-line-args--CommandLineArgs_new"></a>
#### new CommandLineArgs(definitions)
The constructor will throw if you pass invalid option definitions. You should fix these issues before proceeding.
**Throws**:

@@ -174,15 +175,15 @@

## OptionDefinition ⏏
Describes a command-line option.
Describes a command-line option. The additional properties `description` and `typeLabel` used by [.getUsage()](#module_command-line-args--CommandLineArgs+getUsage) are described [here](https://github.com/75lb/command-line-usage#getusagedefinitions-options--string-).
**Kind**: Exported class
* [OptionDefinition](#exp_module_definition--OptionDefinition) ⏏
* [.name](#module_definition--OptionDefinition+name) : <code>string</code>
* [.type](#module_definition--OptionDefinition+type) : <code>function</code>
* [.alias](#module_definition--OptionDefinition+alias) : <code>string</code>
* [.multiple](#module_definition--OptionDefinition+multiple) : <code>boolean</code>
* [.defaultOption](#module_definition--OptionDefinition+defaultOption) : <code>boolean</code>
* [.defaultValue](#module_definition--OptionDefinition+defaultValue) : <code>\*</code>
* [.group](#module_definition--OptionDefinition+group) : <code>string</code> &#124; <code>Array.&lt;string&gt;</code>
* [.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> &#124; <code>Array.&lt;string&gt;</code>
<a name="module_definition--OptionDefinition+name"></a>
<a name="module_definition--OptionDefinition.OptionDefinition+name"></a>
### option.name : <code>string</code>

@@ -217,3 +218,3 @@ The only required definition property is `name`, so the simplest working example is

**Kind**: instance property of <code>[OptionDefinition](#exp_module_definition--OptionDefinition)</code>
<a name="module_definition--OptionDefinition+type"></a>
<a name="module_definition--OptionDefinition.OptionDefinition+type"></a>
### option.type : <code>function</code>

@@ -251,3 +252,3 @@ The `type` value is a setter function (you receive the output from this), enabling you to be specific about the type and value received.

**Kind**: instance property of <code>[OptionDefinition](#exp_module_definition--OptionDefinition)</code>
<a name="module_definition--OptionDefinition+alias"></a>
<a name="module_definition--OptionDefinition.OptionDefinition+alias"></a>
### option.alias : <code>string</code>

@@ -270,5 +271,5 @@ getopt-style short option names. Can be any single character (unicode included) except a digit or hypen.

**Kind**: instance property of <code>[OptionDefinition](#exp_module_definition--OptionDefinition)</code>
<a name="module_definition--OptionDefinition+multiple"></a>
<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 passed through the `type` function (if specified).
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).

@@ -288,3 +289,3 @@ ```js

**Kind**: instance property of <code>[OptionDefinition](#exp_module_definition--OptionDefinition)</code>
<a name="module_definition--OptionDefinition+defaultOption"></a>
<a name="module_definition--OptionDefinition.OptionDefinition+defaultOption"></a>
### option.defaultOption : <code>boolean</code>

@@ -306,3 +307,3 @@ 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`).

**Kind**: instance property of <code>[OptionDefinition](#exp_module_definition--OptionDefinition)</code>
<a name="module_definition--OptionDefinition+defaultValue"></a>
<a name="module_definition--OptionDefinition.OptionDefinition+defaultValue"></a>
### option.defaultValue : <code>\*</code>

@@ -325,3 +326,3 @@ An initial value for the option.

**Kind**: instance property of <code>[OptionDefinition](#exp_module_definition--OptionDefinition)</code>
<a name="module_definition--OptionDefinition+group"></a>
<a name="module_definition--OptionDefinition.OptionDefinition+group"></a>
### option.group : <code>string</code> &#124; <code>Array.&lt;string&gt;</code>

@@ -328,0 +329,0 @@ When your app has a large amount of options it makes sense to organise them in groups.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc