command-line-args
Advanced tools
Comparing version 5.1.1 to 5.1.2
@@ -1,6 +0,6 @@ | ||
'use strict'; | ||
'use strict' | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex.default : ex } | ||
var camelCase = _interopDefault(require('lodash.camelcase')); | ||
const camelCase = _interopDefault(require('lodash.camelcase')) | ||
@@ -58,3 +58,3 @@ /** | ||
} else { | ||
return [ input ] | ||
return [input] | ||
} | ||
@@ -115,3 +115,3 @@ } | ||
} else { | ||
return [ input ] | ||
return [input] | ||
} | ||
@@ -150,15 +150,15 @@ } | ||
function findReplace (array, testFn) { | ||
const found = []; | ||
const replaceWiths = arrayify$1(arguments); | ||
replaceWiths.splice(0, 2); | ||
const found = [] | ||
const replaceWiths = arrayify$1(arguments) | ||
replaceWiths.splice(0, 2) | ||
arrayify$1(array).forEach((value, index) => { | ||
let expanded = []; | ||
let expanded = [] | ||
replaceWiths.forEach(replaceWith => { | ||
if (typeof replaceWith === 'function') { | ||
expanded = expanded.concat(replaceWith(value)); | ||
expanded = expanded.concat(replaceWith(value)) | ||
} else { | ||
expanded.push(replaceWith); | ||
expanded.push(replaceWith) | ||
} | ||
}); | ||
}) | ||
@@ -169,10 +169,10 @@ if (testFn(value)) { | ||
replaceWithValue: expanded | ||
}); | ||
}) | ||
} | ||
}); | ||
}) | ||
found.reverse().forEach(item => { | ||
const spliceArgs = [ item.index, 1 ].concat(item.replaceWithValue); | ||
array.splice.apply(array, spliceArgs); | ||
}); | ||
const spliceArgs = [item.index, 1].concat(item.replaceWithValue) | ||
array.splice.apply(array, spliceArgs) | ||
}) | ||
@@ -200,3 +200,3 @@ return array | ||
optEquals: /^(--\S+?)=(.*)/ | ||
}; | ||
} | ||
@@ -213,12 +213,12 @@ /** | ||
load (argv) { | ||
this.clear(); | ||
this.clear() | ||
if (argv && argv !== process.argv) { | ||
argv = arrayify(argv); | ||
argv = arrayify(argv) | ||
} else { | ||
/* if no argv supplied, assume we are parsing process.argv */ | ||
argv = process.argv.slice(0); | ||
const deleteCount = process.execArgv.some(isExecArg) ? 1 : 2; | ||
argv.splice(0, deleteCount); | ||
argv = process.argv.slice(0) | ||
const deleteCount = process.execArgv.some(isExecArg) ? 1 : 2 | ||
argv.splice(0, deleteCount) | ||
} | ||
argv.forEach(arg => this.push(String(arg))); | ||
argv.forEach(arg => this.push(String(arg))) | ||
} | ||
@@ -230,3 +230,3 @@ | ||
clear () { | ||
this.length = 0; | ||
this.length = 0 | ||
} | ||
@@ -239,13 +239,13 @@ | ||
if (this.some(arg => re.optEquals.test(arg))) { | ||
const expandedArgs = []; | ||
const expandedArgs = [] | ||
this.forEach(arg => { | ||
const matches = arg.match(re.optEquals); | ||
const matches = arg.match(re.optEquals) | ||
if (matches) { | ||
expandedArgs.push(matches[1], matches[2]); | ||
expandedArgs.push(matches[1], matches[2]) | ||
} else { | ||
expandedArgs.push(arg); | ||
expandedArgs.push(arg) | ||
} | ||
}); | ||
this.clear(); | ||
this.load(expandedArgs); | ||
}) | ||
this.clear() | ||
this.load(expandedArgs) | ||
} | ||
@@ -259,3 +259,3 @@ } | ||
if (this.hasCombinedShortOptions()) { | ||
findReplace(this, re.combinedShort, expandCombinedShortArg); | ||
findReplace(this, re.combinedShort, expandCombinedShortArg) | ||
} | ||
@@ -273,4 +273,4 @@ } | ||
static from (argv) { | ||
const result = new this(); | ||
result.load(argv); | ||
const result = new this() | ||
result.load(argv) | ||
return result | ||
@@ -288,3 +288,3 @@ } | ||
/* remove initial hypen */ | ||
arg = arg.slice(1); | ||
arg = arg.slice(1) | ||
return arg.split('').map(letter => '-' + letter) | ||
@@ -522,4 +522,4 @@ } | ||
if (input) { | ||
const isPromise = isDefined(Promise) && input instanceof Promise; | ||
const isThenable = input.then && typeof input.then === 'function'; | ||
const isPromise = isDefined(Promise) && input instanceof Promise | ||
const isThenable = input.then && typeof input.then === 'function' | ||
return !!(isPromise || isThenable) | ||
@@ -581,3 +581,3 @@ } else { | ||
var t = { | ||
const t = { | ||
isNumber, | ||
@@ -595,3 +595,3 @@ isString, | ||
isIterable | ||
}; | ||
} | ||
@@ -637,3 +637,3 @@ /** | ||
*/ | ||
this.name = definition.name; | ||
this.name = definition.name | ||
@@ -675,3 +675,3 @@ /** | ||
*/ | ||
this.type = definition.type || String; | ||
this.type = definition.type || String | ||
@@ -696,3 +696,3 @@ /** | ||
*/ | ||
this.alias = definition.alias; | ||
this.alias = definition.alias | ||
@@ -718,3 +718,3 @@ /** | ||
*/ | ||
this.multiple = definition.multiple; | ||
this.multiple = definition.multiple | ||
@@ -738,3 +738,3 @@ /** | ||
*/ | ||
this.lazyMultiple = definition.lazyMultiple; | ||
this.lazyMultiple = definition.lazyMultiple | ||
@@ -758,3 +758,3 @@ /** | ||
*/ | ||
this.defaultOption = definition.defaultOption; | ||
this.defaultOption = definition.defaultOption | ||
@@ -779,3 +779,3 @@ /** | ||
*/ | ||
this.defaultValue = definition.defaultValue; | ||
this.defaultValue = definition.defaultValue | ||
@@ -845,7 +845,7 @@ /** | ||
*/ | ||
this.group = definition.group; | ||
this.group = definition.group | ||
/* pick up any remaining properties */ | ||
for (let prop in definition) { | ||
if (!this[prop]) this[prop] = definition[prop]; | ||
for (const prop in definition) { | ||
if (!this[prop]) this[prop] = definition[prop] | ||
} | ||
@@ -857,2 +857,3 @@ } | ||
} | ||
isMultiple () { | ||
@@ -863,3 +864,3 @@ return this.multiple || this.lazyMultiple | ||
static create (def) { | ||
const result = new this(def); | ||
const result = new this(def) | ||
return result | ||
@@ -882,3 +883,3 @@ } | ||
validate () { | ||
const someHaveNoName = this.some(def => !def.name); | ||
const someHaveNoName = this.some(def => !def.name) | ||
if (someHaveNoName) { | ||
@@ -888,6 +889,6 @@ halt( | ||
'Invalid option definitions: the `name` property is required on each definition' | ||
); | ||
) | ||
} | ||
const someDontHaveFunctionType = this.some(def => def.type && typeof def.type !== 'function'); | ||
const someDontHaveFunctionType = this.some(def => def.type && typeof def.type !== 'function') | ||
if (someDontHaveFunctionType) { | ||
@@ -897,11 +898,11 @@ halt( | ||
'Invalid option definitions: the `type` property must be a setter fuction (default: `Boolean`)' | ||
); | ||
) | ||
} | ||
let invalidOption; | ||
let invalidOption | ||
const numericAlias = this.some(def => { | ||
invalidOption = def; | ||
invalidOption = def | ||
return t.isDefined(def.alias) && t.isNumber(def.alias) | ||
}); | ||
}) | ||
if (numericAlias) { | ||
@@ -911,9 +912,9 @@ halt( | ||
'Invalid option definition: to avoid ambiguity an alias cannot be numeric [--' + invalidOption.name + ' alias is -' + invalidOption.alias + ']' | ||
); | ||
) | ||
} | ||
const multiCharacterAlias = this.some(def => { | ||
invalidOption = def; | ||
invalidOption = def | ||
return t.isDefined(def.alias) && def.alias.length !== 1 | ||
}); | ||
}) | ||
if (multiCharacterAlias) { | ||
@@ -923,9 +924,9 @@ halt( | ||
'Invalid option definition: an alias must be a single character' | ||
); | ||
) | ||
} | ||
const hypenAlias = this.some(def => { | ||
invalidOption = def; | ||
invalidOption = def | ||
return def.alias === '-' | ||
}); | ||
}) | ||
if (hypenAlias) { | ||
@@ -935,6 +936,6 @@ halt( | ||
'Invalid option definition: an alias cannot be "-"' | ||
); | ||
) | ||
} | ||
const duplicateName = hasDuplicates(this.map(def => def.name)); | ||
const duplicateName = hasDuplicates(this.map(def => def.name)) | ||
if (duplicateName) { | ||
@@ -944,6 +945,6 @@ halt( | ||
'Two or more option definitions have the same name' | ||
); | ||
) | ||
} | ||
const duplicateAlias = hasDuplicates(this.map(def => def.alias)); | ||
const duplicateAlias = hasDuplicates(this.map(def => def.alias)) | ||
if (duplicateAlias) { | ||
@@ -953,6 +954,6 @@ halt( | ||
'Two or more option definitions have the same alias' | ||
); | ||
) | ||
} | ||
const duplicateDefaultOption = hasDuplicates(this.map(def => def.defaultOption)); | ||
const duplicateDefaultOption = hasDuplicates(this.map(def => def.defaultOption)) | ||
if (duplicateDefaultOption) { | ||
@@ -962,9 +963,9 @@ halt( | ||
'Only one option definition can be the defaultOption' | ||
); | ||
) | ||
} | ||
const defaultBoolean = this.some(def => { | ||
invalidOption = def; | ||
invalidOption = def | ||
return def.isBoolean() && def.defaultOption | ||
}); | ||
}) | ||
if (defaultBoolean) { | ||
@@ -974,3 +975,3 @@ halt( | ||
`A boolean option ["${invalidOption.name}"] can not also be the defaultOption.` | ||
); | ||
) | ||
} | ||
@@ -1005,5 +1006,7 @@ } | ||
} | ||
whereNotGrouped () { | ||
return this.filter(def => !containsValidGroup(def)) | ||
} | ||
whereDefaultValueSet () { | ||
@@ -1015,4 +1018,4 @@ return this.filter(def => t.isDefined(def.defaultValue)) | ||
if (definitions instanceof this) return definitions | ||
const result = super.from(arrayify(definitions), def => OptionDefinition.create(def)); | ||
result.validate(); | ||
const result = super.from(arrayify(definitions), def => OptionDefinition.create(def)) | ||
result.validate() | ||
return result | ||
@@ -1023,4 +1026,4 @@ } | ||
function halt (name, message) { | ||
const err = new Error(message); | ||
err.name = name; | ||
const err = new Error(message) | ||
err.name = name | ||
throw err | ||
@@ -1034,9 +1037,9 @@ } | ||
function hasDuplicates (array) { | ||
const items = {}; | ||
const items = {} | ||
for (let i = 0; i < array.length; i++) { | ||
const value = array[i]; | ||
const value = array[i] | ||
if (items[value]) { | ||
return true | ||
} else { | ||
if (t.isDefined(value)) items[value] = true; | ||
if (t.isDefined(value)) items[value] = true | ||
} | ||
@@ -1061,7 +1064,7 @@ } | ||
constructor (definitions, options) { | ||
this.options = Object.assign({}, options); | ||
this.options = Object.assign({}, options) | ||
/** | ||
* Option Definitions | ||
*/ | ||
this.definitions = Definitions.from(definitions); | ||
this.definitions = Definitions.from(definitions) | ||
@@ -1071,8 +1074,8 @@ /** | ||
*/ | ||
this.argv = ArgvArray.from(this.options.argv); | ||
this.argv = ArgvArray.from(this.options.argv) | ||
if (this.argv.hasCombinedShortOptions()) { | ||
findReplace(this.argv, re.combinedShort.test.bind(re.combinedShort), arg => { | ||
arg = arg.slice(1); | ||
arg = arg.slice(1) | ||
return arg.split('').map(letter => ({ origArg: `-${arg}`, arg: '-' + letter })) | ||
}); | ||
}) | ||
} | ||
@@ -1085,20 +1088,20 @@ } | ||
* [Symbol.iterator] () { | ||
const definitions = this.definitions; | ||
const definitions = this.definitions | ||
let def; | ||
let value; | ||
let name; | ||
let event; | ||
let singularDefaultSet = false; | ||
let unknownFound = false; | ||
let origArg; | ||
let def | ||
let value | ||
let name | ||
let event | ||
let singularDefaultSet = false | ||
let unknownFound = false | ||
let origArg | ||
for (let arg of this.argv) { | ||
if (t.isPlainObject(arg)) { | ||
origArg = arg.origArg; | ||
arg = arg.arg; | ||
origArg = arg.origArg | ||
arg = arg.arg | ||
} | ||
if (unknownFound && this.options.stopAtFirstUnknown) { | ||
yield { event: 'unknown_value', arg, name: '_unknown', value: undefined }; | ||
yield { event: 'unknown_value', arg, name: '_unknown', value: undefined } | ||
continue | ||
@@ -1109,42 +1112,42 @@ } | ||
if (isOption(arg)) { | ||
def = definitions.get(arg); | ||
value = undefined; | ||
def = definitions.get(arg) | ||
value = undefined | ||
if (def) { | ||
value = def.isBoolean() ? true : null; | ||
event = 'set'; | ||
value = def.isBoolean() ? true : null | ||
event = 'set' | ||
} else { | ||
event = 'unknown_option'; | ||
event = 'unknown_option' | ||
} | ||
/* handle --option-value notation */ | ||
} else if (isOptionEqualsNotation(arg)) { | ||
const matches = arg.match(re.optEquals); | ||
def = definitions.get(matches[1]); | ||
} else if (isOptionEqualsNotation(arg)) { | ||
const matches = arg.match(re.optEquals) | ||
def = definitions.get(matches[1]) | ||
if (def) { | ||
if (def.isBoolean()) { | ||
yield { event: 'unknown_value', arg, name: '_unknown', value, def }; | ||
event = 'set'; | ||
value = true; | ||
yield { event: 'unknown_value', arg, name: '_unknown', value, def } | ||
event = 'set' | ||
value = true | ||
} else { | ||
event = 'set'; | ||
value = matches[2]; | ||
event = 'set' | ||
value = matches[2] | ||
} | ||
} else { | ||
event = 'unknown_option'; | ||
event = 'unknown_option' | ||
} | ||
/* handle value */ | ||
} else if (isValue(arg)) { | ||
} else if (isValue(arg)) { | ||
if (def) { | ||
value = arg; | ||
event = 'set'; | ||
value = arg | ||
event = 'set' | ||
} else { | ||
/* get the defaultOption */ | ||
def = this.definitions.getDefault(); | ||
def = this.definitions.getDefault() | ||
if (def && !singularDefaultSet) { | ||
value = arg; | ||
event = 'set'; | ||
value = arg | ||
event = 'set' | ||
} else { | ||
event = 'unknown_value'; | ||
def = undefined; | ||
event = 'unknown_value' | ||
def = undefined | ||
} | ||
@@ -1154,26 +1157,26 @@ } | ||
name = def ? def.name : '_unknown'; | ||
const argInfo = { event, arg, name, value, def }; | ||
name = def ? def.name : '_unknown' | ||
const argInfo = { event, arg, name, value, def } | ||
if (origArg) { | ||
argInfo.subArg = arg; | ||
argInfo.arg = origArg; | ||
argInfo.subArg = arg | ||
argInfo.arg = origArg | ||
} | ||
yield argInfo; | ||
yield argInfo | ||
/* unknownFound logic */ | ||
if (name === '_unknown') unknownFound = true; | ||
if (name === '_unknown') unknownFound = true | ||
/* singularDefaultSet logic */ | ||
if (def && def.defaultOption && !def.isMultiple() && event === 'set') singularDefaultSet = true; | ||
if (def && def.defaultOption && !def.isMultiple() && event === 'set') singularDefaultSet = true | ||
/* reset values once consumed and yielded */ | ||
if (def && def.isBoolean()) def = undefined; | ||
if (def && def.isBoolean()) def = undefined | ||
/* reset the def if it's a singular which has been set */ | ||
if (def && !def.multiple && t.isDefined(value) && value !== null) { | ||
def = undefined; | ||
def = undefined | ||
} | ||
value = undefined; | ||
event = undefined; | ||
name = undefined; | ||
origArg = undefined; | ||
value = undefined | ||
event = undefined | ||
name = undefined | ||
origArg = undefined | ||
} | ||
@@ -1183,3 +1186,3 @@ } | ||
const _value = new WeakMap(); | ||
const _value = new WeakMap() | ||
@@ -1191,5 +1194,5 @@ /** | ||
constructor (definition) { | ||
this.definition = new OptionDefinition(definition); | ||
this.state = null; /* set or default */ | ||
this.resetToDefault(); | ||
this.definition = new OptionDefinition(definition) | ||
this.state = null /* set or default */ | ||
this.resetToDefault() | ||
} | ||
@@ -1202,14 +1205,14 @@ | ||
set (val) { | ||
this._set(val, 'set'); | ||
this._set(val, 'set') | ||
} | ||
_set (val, state) { | ||
const def = this.definition; | ||
const def = this.definition | ||
if (def.isMultiple()) { | ||
/* don't add null or undefined to a multiple */ | ||
if (val !== null && val !== undefined) { | ||
const arr = this.get(); | ||
if (this.state === 'default') arr.length = 0; | ||
arr.push(def.type(val)); | ||
this.state = state; | ||
const arr = this.get() | ||
if (this.state === 'default') arr.length = 0 | ||
arr.push(def.type(val)) | ||
this.state = state | ||
} | ||
@@ -1219,9 +1222,9 @@ } else { | ||
if (!def.isMultiple() && this.state === 'set') { | ||
const err = new Error(`Singular option already set [${this.definition.name}=${this.get()}]`); | ||
err.name = 'ALREADY_SET'; | ||
err.value = val; | ||
err.optionName = def.name; | ||
const err = new Error(`Singular option already set [${this.definition.name}=${this.get()}]`) | ||
err.name = 'ALREADY_SET' | ||
err.value = val | ||
err.optionName = def.name | ||
throw err | ||
} else if (val === null || val === undefined) { | ||
_value.set(this, val); | ||
_value.set(this, val) | ||
// /* required to make 'partial: defaultOption with value equal to defaultValue 2' pass */ | ||
@@ -1232,4 +1235,4 @@ // if (!(def.defaultOption && !def.isMultiple())) { | ||
} else { | ||
_value.set(this, def.type(val)); | ||
this.state = state; | ||
_value.set(this, def.type(val)) | ||
this.state = state | ||
} | ||
@@ -1242,18 +1245,18 @@ } | ||
if (this.definition.isMultiple()) { | ||
_value.set(this, arrayify(this.definition.defaultValue).slice()); | ||
_value.set(this, arrayify(this.definition.defaultValue).slice()) | ||
} else { | ||
_value.set(this, this.definition.defaultValue); | ||
_value.set(this, this.definition.defaultValue) | ||
} | ||
} else { | ||
if (this.definition.isMultiple()) { | ||
_value.set(this, []); | ||
_value.set(this, []) | ||
} else { | ||
_value.set(this, null); | ||
_value.set(this, null) | ||
} | ||
} | ||
this.state = 'default'; | ||
this.state = 'default' | ||
} | ||
static create (definition) { | ||
definition = new OptionDefinition(definition); | ||
definition = new OptionDefinition(definition) | ||
if (definition.isBoolean()) { | ||
@@ -1269,3 +1272,3 @@ return FlagOption.create(definition) | ||
set (val) { | ||
super.set(true); | ||
super.set(true) | ||
} | ||
@@ -1283,12 +1286,12 @@ | ||
constructor (definitions) { | ||
super(); | ||
super() | ||
/** | ||
* @type {OptionDefinitions} | ||
*/ | ||
this.definitions = Definitions.from(definitions); | ||
this.definitions = Definitions.from(definitions) | ||
/* by default, an Output has an `_unknown` property and any options with defaultValues */ | ||
this.set('_unknown', Option.create({ name: '_unknown', multiple: true })); | ||
this.set('_unknown', Option.create({ name: '_unknown', multiple: true })) | ||
for (const def of this.definitions.whereDefaultValueSet()) { | ||
this.set(def.name, Option.create(def)); | ||
this.set(def.name, Option.create(def)) | ||
} | ||
@@ -1298,12 +1301,12 @@ } | ||
toObject (options) { | ||
options = options || {}; | ||
const output = {}; | ||
options = options || {} | ||
const output = {} | ||
for (const item of this) { | ||
const name = options.camelCase && item[0] !== '_unknown' ? camelCase(item[0]) : item[0]; | ||
const option = item[1]; | ||
const name = options.camelCase && item[0] !== '_unknown' ? camelCase(item[0]) : item[0] | ||
const option = item[1] | ||
if (name === '_unknown' && !option.get().length) continue | ||
output[name] = option.get(); | ||
output[name] = option.get() | ||
} | ||
if (options.skipUnknown) delete output._unknown; | ||
if (options.skipUnknown) delete output._unknown | ||
return output | ||
@@ -1315,30 +1318,30 @@ } | ||
toObject (options) { | ||
const superOutputNoCamel = super.toObject({ skipUnknown: options.skipUnknown }); | ||
const superOutput = super.toObject(options); | ||
const unknown = superOutput._unknown; | ||
delete superOutput._unknown; | ||
const superOutputNoCamel = super.toObject({ skipUnknown: options.skipUnknown }) | ||
const superOutput = super.toObject(options) | ||
const unknown = superOutput._unknown | ||
delete superOutput._unknown | ||
const grouped = { | ||
_all: superOutput | ||
}; | ||
if (unknown && unknown.length) grouped._unknown = unknown; | ||
} | ||
if (unknown && unknown.length) grouped._unknown = unknown | ||
this.definitions.whereGrouped().forEach(def => { | ||
const name = options.camelCase ? camelCase(def.name) : def.name; | ||
const outputValue = superOutputNoCamel[def.name]; | ||
const name = options.camelCase ? camelCase(def.name) : def.name | ||
const outputValue = superOutputNoCamel[def.name] | ||
for (const groupName of arrayify(def.group)) { | ||
grouped[groupName] = grouped[groupName] || {}; | ||
grouped[groupName] = grouped[groupName] || {} | ||
if (t.isDefined(outputValue)) { | ||
grouped[groupName][name] = outputValue; | ||
grouped[groupName][name] = outputValue | ||
} | ||
} | ||
}); | ||
}) | ||
this.definitions.whereNotGrouped().forEach(def => { | ||
const name = options.camelCase ? camelCase(def.name) : def.name; | ||
const outputValue = superOutputNoCamel[def.name]; | ||
const name = options.camelCase ? camelCase(def.name) : def.name | ||
const outputValue = superOutputNoCamel[def.name] | ||
if (t.isDefined(outputValue)) { | ||
if (!grouped._none) grouped._none = {}; | ||
grouped._none[name] = outputValue; | ||
if (!grouped._none) grouped._none = {} | ||
grouped._none[name] = outputValue | ||
} | ||
}); | ||
}) | ||
return grouped | ||
@@ -1378,5 +1381,5 @@ } | ||
function commandLineArgs (optionDefinitions, options) { | ||
options = options || {}; | ||
if (options.stopAtFirstUnknown) options.partial = true; | ||
optionDefinitions = Definitions.from(optionDefinitions); | ||
options = options || {} | ||
if (options.stopAtFirstUnknown) options.partial = true | ||
optionDefinitions = Definitions.from(optionDefinitions) | ||
@@ -1386,20 +1389,20 @@ const parser = new ArgvParser(optionDefinitions, { | ||
stopAtFirstUnknown: options.stopAtFirstUnknown | ||
}); | ||
}) | ||
const OutputClass = optionDefinitions.isGrouped() ? GroupedOutput : Output; | ||
const output = new OutputClass(optionDefinitions); | ||
const OutputClass = optionDefinitions.isGrouped() ? GroupedOutput : Output | ||
const output = new OutputClass(optionDefinitions) | ||
/* Iterate the parser setting each known value to the output. Optionally, throw on unknowns. */ | ||
for (const argInfo of parser) { | ||
const arg = argInfo.subArg || argInfo.arg; | ||
const arg = argInfo.subArg || argInfo.arg | ||
if (!options.partial) { | ||
if (argInfo.event === 'unknown_value') { | ||
const err = new Error(`Unknown value: ${arg}`); | ||
err.name = 'UNKNOWN_VALUE'; | ||
err.value = arg; | ||
const err = new Error(`Unknown value: ${arg}`) | ||
err.name = 'UNKNOWN_VALUE' | ||
err.value = arg | ||
throw err | ||
} else if (argInfo.event === 'unknown_option') { | ||
const err = new Error(`Unknown option: ${arg}`); | ||
err.name = 'UNKNOWN_OPTION'; | ||
err.optionName = arg; | ||
const err = new Error(`Unknown option: ${arg}`) | ||
err.name = 'UNKNOWN_OPTION' | ||
err.optionName = arg | ||
throw err | ||
@@ -1409,14 +1412,14 @@ } | ||
let option; | ||
let option | ||
if (output.has(argInfo.name)) { | ||
option = output.get(argInfo.name); | ||
option = output.get(argInfo.name) | ||
} else { | ||
option = Option.create(argInfo.def); | ||
output.set(argInfo.name, option); | ||
option = Option.create(argInfo.def) | ||
output.set(argInfo.name, option) | ||
} | ||
if (argInfo.name === '_unknown') { | ||
option.set(arg); | ||
option.set(arg) | ||
} else { | ||
option.set(argInfo.value); | ||
option.set(argInfo.value) | ||
} | ||
@@ -1428,2 +1431,2 @@ } | ||
module.exports = commandLineArgs; | ||
module.exports = commandLineArgs |
{ | ||
"name": "command-line-args", | ||
"version": "5.1.1", | ||
"version": "5.1.2", | ||
"description": "A mature, feature-complete library to parse command-line options.", | ||
"repository": "https://github.com/75lb/command-line-args.git", | ||
"repository": "https://github.com/75lb/command-line-args", | ||
"scripts": { | ||
@@ -41,13 +41,19 @@ "test": "npm run test:js && npm run test:mjs", | ||
"devDependencies": { | ||
"coveralls": "^3.0.3", | ||
"coveralls": "^3.1.1", | ||
"jsdoc-to-markdown": "^4.0.1", | ||
"rollup": "^1.7.4", | ||
"rollup": "~1.7.4", | ||
"test-runner": "^0.5.1" | ||
}, | ||
"dependencies": { | ||
"array-back": "^3.0.1", | ||
"array-back": "^6.1.2", | ||
"find-replace": "^3.0.0", | ||
"lodash.camelcase": "^4.3.0", | ||
"typical": "^4.0.0" | ||
}, | ||
"standard": { | ||
"ignore": [ | ||
"dist" | ||
], | ||
"envs": [] | ||
} | ||
} |
@@ -1,8 +0,8 @@ | ||
[![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) | ||
[![view on npm](https://badgen.net/npm/v/command-line-args)](https://www.npmjs.org/package/command-line-args) | ||
[![npm module downloads](https://badgen.net/npm/dt/command-line-args)](https://www.npmjs.org/package/command-line-args) | ||
[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/command-line-args)](https://github.com/75lb/command-line-args/network/dependents?dependent_type=REPOSITORY) | ||
[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/command-line-args)](https://github.com/75lb/command-line-args/network/dependents?dependent_type=PACKAGE) | ||
[![Node.js CI](https://github.com/75lb/command-line-args/actions/workflows/node.js.yml/badge.svg)](https://github.com/75lb/command-line-args/actions/workflows/node.js.yml) | ||
[![Coverage Status](https://coveralls.io/repos/github/75lb/command-line-args/badge.svg)](https://coveralls.io/github/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) | ||
@@ -12,5 +12,7 @@ ***Upgraders, please read the [release notes](https://github.com/75lb/command-line-args/releases)*** | ||
# command-line-args | ||
A mature, feature-complete library to parse command-line options. | ||
## Synopsis | ||
You can set options using the main notation standards ([learn more](https://github.com/75lb/command-line-args/wiki/Notation-rules)). These commands are all equivalent, setting the same values: | ||
@@ -104,2 +106,2 @@ ``` | ||
© 2014-19 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown). | ||
© 2014-21 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
106
111534
+ Addedarray-back@6.2.2(transitive)
Updatedarray-back@^6.1.2