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 5.0.2 to 6.0.0-preview.1

43

lib/argv-parser.js

@@ -16,3 +16,3 @@ 'use strict'

* @param {string[]} [options.argv] - Overrides `process.argv`
* @param {boolean} [options.stopAtFirstUnknown] -
* @param {boolean} [options.stopAtFirstUnknown]
*/

@@ -24,2 +24,3 @@ constructor (definitions, options) {

* Option Definitions
* @type {OptionDefinition[]}
*/

@@ -30,16 +31,36 @@ this.definitions = Definitions.from(definitions)

* Argv
* @type {Array<string|object>}
*/
this.argv = argvTools.ArgvArray.from(this.options.argv)
if (this.argv.hasCombinedShortOptions()) {
const findReplace = require('find-replace')
findReplace(this.argv, argvTools.re.combinedShort, arg => {
arg = arg.slice(1)
return arg.split('').map(letter => ({ origArg: `-${arg}`, arg: '-' + letter }))
})
this.expandCluster()
}
}
/**
* Yields one `{ event, name, value, arg, def }` argInfo object for each arg in `process.argv` (or `options.argv`).
*/
expandCluster () {
const findReplace = require('find-replace')
findReplace(this.argv, argvTools.re.combinedShort, arg => {
const result = []
arg = arg.slice(1)
for (const letter of arg.split('')) {
const def = this.definitions.get(`-${letter}`)
if (def) {
if (def.isBoolean()) {
result.push({ origArg: `-${arg}`, arg: `-${letter}` })
} else {
result.push({ origArg: `-${arg}`, arg: `-${letter}` })
const attachedValue = arg.slice(arg.indexOf(letter) + 1)
if (attachedValue) {
result.push({ origArg: `-${arg}`, arg: attachedValue })
}
break
}
} else {
result.push({ origArg: `-${arg}`, arg: `-${letter}` })
}
}
return result
})
}
* [Symbol.iterator] () {

@@ -80,3 +101,3 @@ const definitions = this.definitions

/* handle --option-value notation */
} else if (argvTools.isOptionEqualsNotation(arg)) {
} else if (argvTools.isOptionEqualsNotation(arg)) {
const matches = arg.match(argvTools.re.optEquals)

@@ -98,3 +119,3 @@ def = definitions.get(matches[1])

/* handle value */
} else if (argvTools.isValue(arg)) {
} else if (argvTools.isValue(arg)) {
if (def) {

@@ -101,0 +122,0 @@ value = arg

@@ -27,3 +27,3 @@ 'use strict'

*
* | # | Command line args | .parse() output |
* | # | argv input | commandLineArgs() output |
* | --- | -------------------- | ------------ |

@@ -67,3 +67,3 @@ * | 1 | `--file` | `{ file: null }` |

*
* | # | Command line args| .parse() output |
* | # | argv input | commandLineArgs() output |
* | --- | ----------------- | ------------ |

@@ -74,3 +74,3 @@ * | 1 | `--file asdf.txt` | `{ file: { filename: 'asdf.txt', exists: false } }` |

*
* | # | Command line args | .parse() output |
* | # | argv input | commandLineArgs() output |
* | --- | ----------------- | ------------ |

@@ -96,3 +96,3 @@ * | 2 | `--depth` | `{ depth: null }` |

*
* | # | Command line | .parse() output |
* | # | argv input | commandLineArgs() output |
* | --- | ------------ | ------------ |

@@ -117,3 +117,3 @@ * | 1 | `-hcd` | `{ hot: true, courses: null, discount: true }` |

*
* | # | Command line | .parse() output |
* | # | argv input | commandLineArgs() output |
* | --- | ------------ | ------------ |

@@ -138,3 +138,3 @@ * | 1 | `--files one.js two.js` | `{ files: [ 'one.js', 'two.js' ] }` |

*
* | # | Command line | .parse() output |
* | # | argv input | commandLineArgs() output |
* | --- | ------------ | ------------ |

@@ -157,3 +157,3 @@ * | 1 | `--files one.js --files two.js` | `{ files: [ 'one.js', 'two.js' ] }` |

*
* | # | Command line | .parse() output |
* | # | argv input | commandLineArgs() output |
* | --- | ------------ | ------------ |

@@ -178,3 +178,3 @@ * | 1 | `--files one.js two.js` | `{ files: [ 'one.js', 'two.js' ] }` |

*
* | # | Command line | .parse() output |
* | # | argv input | commandLineArgs() output |
* | --- | ------------ | ------------ |

@@ -206,3 +206,3 @@ * | 1 | | `{ files: [ 'one.js' ], max: 3 }` |

* <tr>
* <th>#</th><th>Command Line</th><th>.parse() output</th>
* <th>#</th><th>Command Line</th><th>commandLineArgs() output</th>
* </tr>

@@ -209,0 +209,0 @@ * <tr>

{
"name": "command-line-args",
"version": "5.0.2",
"version": "6.0.0-preview.1",
"description": "A mature, feature-complete library to parse command-line options.",

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

"docs": "jsdoc2md index.js > doc/API.md && jsdoc2md lib/option-definition.js > doc/option-definition.md",
"cover": "istanbul cover ./node_modules/.bin/test-runner test/*.js test/internals/*.js && cat coverage/lcov.info | ./node_modules/.bin/coveralls #&& rm -rf coverage; echo"
"cover": "nyc --reporter=text-lcov test-runner test/*.js test/internals/*.js | coveralls"
},

@@ -30,2 +30,6 @@ "keywords": [

},
"files": [
"index.js",
"lib"
],
"devDependencies": {

@@ -32,0 +36,0 @@ "coveralls": "^3.0.0",

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