Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yargs

Package Overview
Dependencies
Maintainers
3
Versions
250
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yargs - npm Package Compare versions

Comparing version 12.0.5 to 13.0.0-candidate.0

lib/decamelize.js

32

lib/command.js
'use strict'
const inspect = require('util').inspect
const isPromise = require('./is-promise')
const {applyMiddleware} = require('./middleware')
const path = require('path')

@@ -18,8 +20,7 @@ const Parser = require('yargs-parser')

globalMiddleware = globalMiddleware || []
self.addHandler = function addHandler (cmd, description, builder, handler, middlewares) {
self.addHandler = function addHandler (cmd, description, builder, handler, _middlewares) {
let aliases = []
const middlewares = (_middlewares || []).slice(0)
handler = handler || (() => {})
middlewares = middlewares || []
globalMiddleware.push(...middlewares)
middlewares = globalMiddleware
if (Array.isArray(cmd)) {

@@ -233,13 +234,14 @@ aliases = cmd.slice(1)

yargs._setHasOutput()
if (commandHandler.middlewares.length > 0) {
const middlewareArgs = commandHandler.middlewares.reduce(function (initialObj, middleware) {
return Object.assign(initialObj, middleware(innerArgv))
}, {})
Object.assign(innerArgv, middlewareArgs)
}
const handlerResult = commandHandler.handler(innerArgv)
if (handlerResult && typeof handlerResult.then === 'function') {
handlerResult.then(
null,
(error) => yargs.getUsageInstance().fail(null, error)
const middlewares = globalMiddleware.slice(0).concat(commandHandler.middlewares || [])
innerArgv = applyMiddleware(innerArgv, middlewares)
const handlerResult = isPromise(innerArgv)
? innerArgv.then(argv => commandHandler.handler(argv))
: commandHandler.handler(innerArgv)
if (isPromise(handlerResult)) {
handlerResult.catch(error =>
yargs.getUsageInstance().fail(null, error)
)

@@ -246,0 +248,0 @@ }

/*
Copyright (c) 2011 Andrei Mackenzie
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:
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 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.
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.
*/

@@ -10,0 +21,0 @@

@@ -0,1 +1,3 @@

const isPromise = require('./is-promise')
module.exports = function (globalMiddleware, context) {

@@ -11,1 +13,22 @@ return function (callback) {

}
module.exports.applyMiddleware = function (argv, middlewares) {
return middlewares
.reduce((accumulation, middleware) => {
if (isPromise(accumulation)) {
return accumulation
.then(initialObj =>
Promise.all([initialObj, middleware(initialObj)])
)
.then(([initialObj, middlewareObj]) =>
Object.assign(initialObj, middlewareObj)
)
} else {
const result = middleware(argv)
return isPromise(result)
? result.then(middlewareObj => Object.assign(accumulation, middlewareObj))
: Object.assign(accumulation, result)
}
}, argv)
}
'use strict'
// this file handles outputting usage instructions,
// failures, etc. keeps logging in one place.
const decamelize = require('./decamelize')
const stringWidth = require('string-width')

@@ -207,2 +208,6 @@ const objFilter = require('./obj-filter')

if (yargs.getParserConfiguration()['sort-commands'] === true) {
commands = commands.sort((a, b) => a[0].localeCompare(b[0]))
}
commands.forEach((command) => {

@@ -432,3 +437,3 @@ const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}` // drop $0 from default commands.

self.functionDescription = (fn) => {
const description = fn.name ? require('decamelize')(fn.name, '-') : __('generated-value')
const description = fn.name ? decamelize(fn.name, '-') : __('generated-value')
return ['(', description, ')'].join('')

@@ -435,0 +440,0 @@ }

{
"name": "yargs",
"version": "12.0.5",
"version": "13.0.0-candidate.0",
"description": "yargs the modern, pirate-themed, successor to optimist.",

@@ -22,28 +22,27 @@ "main": "./index.js",

"cliui": "^4.0.0",
"decamelize": "^1.2.0",
"find-up": "^3.0.0",
"get-caller-file": "^1.0.1",
"os-locale": "^3.0.0",
"get-caller-file": "^2.0.1",
"os-locale": "^3.1.0",
"require-directory": "^2.1.1",
"require-main-filename": "^1.0.1",
"require-main-filename": "^2.0.0",
"set-blocking": "^2.0.0",
"string-width": "^2.0.0",
"string-width": "^3.0.0",
"which-module": "^2.0.0",
"y18n": "^3.2.1 || ^4.0.0",
"yargs-parser": "^11.1.1"
"y18n": "^4.0.0",
"yargs-parser": "^13.0.0"
},
"devDependencies": {
"chai": "^4.1.2",
"chalk": "^1.1.3",
"chai": "^4.2.0",
"chalk": "^2.4.2",
"coveralls": "^3.0.2",
"cpr": "^2.0.0",
"cpr": "^3.0.1",
"cross-spawn": "^6.0.4",
"es6-promise": "^4.0.2",
"es6-promise": "^4.2.5",
"hashish": "0.0.4",
"mocha": "^5.1.1",
"nyc": "^11.7.3",
"rimraf": "^2.5.0",
"mocha": "^5.2.0",
"nyc": "^13.2.0",
"rimraf": "^2.6.3",
"standard": "^11.0.1",
"standard-version": "^4.2.0",
"which": "^1.2.9",
"standard-version": "^4.4.0",
"which": "^1.3.1",
"yargs-test-extends": "^1.0.1"

@@ -53,3 +52,3 @@ },

"pretest": "standard",
"test": "nyc --cache mocha --require ./test/before.js --timeout=8000 --check-leaks",
"test": "nyc --cache mocha --require ./test/before.js --timeout=12000 --check-leaks",
"coverage": "nyc report --reporter=text-lcov | coveralls",

@@ -56,0 +55,0 @@ "release": "standard-version"

@@ -768,2 +768,10 @@ 'use strict'

let parserConfig = {}
self.parserConfiguration = function parserConfiguration (config) {
argsert('<object>', [config], arguments.length)
parserConfig = config
return self
}
self.getParserConfiguration = () => parserConfig
self.showHelp = function (level) {

@@ -1014,4 +1022,11 @@ argsert('[string|function]', [level], arguments.length)

options.__ = y18n.__
options.configuration = pkgUp()['yargs'] || {}
options.configuration = self.getParserConfiguration()
// Deprecated
let pkgConfig = pkgUp()['yargs']
if (pkgConfig) {
console.warn('Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.')
options.configuration = Object.assign({}, pkgConfig, options.configuration)
}
const parsed = Parser.detailed(args, options)

@@ -1157,3 +1172,3 @@ let argv = parsed.argv

self._runValidation = function runValidation (argv, aliases, positionalMap, parseErrors) {
if (parseErrors) throw new YError(parseErrors.message)
if (parseErrors) throw new YError(parseErrors.message || parseErrors)
validation.nonOptionCount(argv)

@@ -1160,0 +1175,0 @@ validation.requiredArguments(argv)

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