Comparing version 12.0.5 to 13.0.0-candidate.0
'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" |
19
yargs.js
@@ -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
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 v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
220886
11
42
3406
1
+ Addedansi-regex@4.1.1(transitive)
+ Addedemoji-regex@7.0.3(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedrequire-main-filename@2.0.0(transitive)
+ Addedstring-width@3.1.0(transitive)
+ Addedstrip-ansi@5.2.0(transitive)
+ Addedyargs-parser@13.1.2(transitive)
- Removeddecamelize@^1.2.0
- Removedget-caller-file@1.0.3(transitive)
- Removedrequire-main-filename@1.0.1(transitive)
- Removedyargs-parser@11.1.1(transitive)
Updatedget-caller-file@^2.0.1
Updatedos-locale@^3.1.0
Updatedrequire-main-filename@^2.0.0
Updatedstring-width@^3.0.0
Updatedy18n@^4.0.0
Updatedyargs-parser@^13.0.0