diff options
Diffstat (limited to 'node_modules/yargs')
-rw-r--r-- | node_modules/yargs/CHANGELOG.md | 74 | ||||
-rw-r--r-- | node_modules/yargs/README.md | 39 | ||||
-rw-r--r-- | node_modules/yargs/lib/apply-extends.js | 8 | ||||
-rw-r--r-- | node_modules/yargs/lib/command.js | 25 | ||||
-rw-r--r-- | node_modules/yargs/lib/usage.js | 31 | ||||
-rw-r--r-- | node_modules/yargs/lib/validation.js | 32 | ||||
-rw-r--r-- | node_modules/yargs/locales/zh_CN.json | 6 | ||||
-rw-r--r-- | node_modules/yargs/package.json | 10 | ||||
-rw-r--r-- | node_modules/yargs/yargs.js | 66 |
9 files changed, 198 insertions, 93 deletions
diff --git a/node_modules/yargs/CHANGELOG.md b/node_modules/yargs/CHANGELOG.md index 8bb58c3f3..f3912fe95 100644 --- a/node_modules/yargs/CHANGELOG.md +++ b/node_modules/yargs/CHANGELOG.md @@ -2,6 +2,80 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +<a name="11.1.0"></a> +# [11.1.0](https://github.com/yargs/yargs/compare/v11.0.0...v11.1.0) (2018-03-04) + + +### Bug Fixes + +* choose correct config directory when require.main does not exist ([#1056](https://github.com/yargs/yargs/issues/1056)) ([a04678c](https://github.com/yargs/yargs/commit/a04678c)) + + +### Features + +* allow hidden options to be displayed with --show-hidden ([#1061](https://github.com/yargs/yargs/issues/1061)) ([ea862ae](https://github.com/yargs/yargs/commit/ea862ae)) +* extend *.rc files in addition to json ([#1080](https://github.com/yargs/yargs/issues/1080)) ([11691a6](https://github.com/yargs/yargs/commit/11691a6)) + + + +<a name="11.0.0"></a> +# [11.0.0](https://github.com/yargs/yargs/compare/v10.1.2...v11.0.0) (2018-01-22) + + +### Bug Fixes + +* Set implicit nargs=1 when type=number requiresArg=true ([#1050](https://github.com/yargs/yargs/issues/1050)) ([2b56812](https://github.com/yargs/yargs/commit/2b56812)) + + +### Features + +* requiresArg is now simply an alias for nargs(1) ([#1054](https://github.com/yargs/yargs/issues/1054)) ([a3ddacc](https://github.com/yargs/yargs/commit/a3ddacc)) + + +### BREAKING CHANGES + +* requiresArg now has significantly different error output, matching nargs. + + + +<a name="10.1.2"></a> +## [10.1.2](https://github.com/yargs/yargs/compare/v10.1.1...v10.1.2) (2018-01-17) + + +### Bug Fixes + +* requiresArg should only be enforced if argument exists ([#1043](https://github.com/yargs/yargs/issues/1043)) ([fbf41ae](https://github.com/yargs/yargs/commit/fbf41ae)) + + + +<a name="10.1.1"></a> +## [10.1.1](https://github.com/yargs/yargs/compare/v10.1.0...v10.1.1) (2018-01-09) + + +### Bug Fixes + +* Add `dirname` sanity check on `findUp` ([#1036](https://github.com/yargs/yargs/issues/1036)) ([331d103](https://github.com/yargs/yargs/commit/331d103)) + + + +<a name="10.1.0"></a> +# [10.1.0](https://github.com/yargs/yargs/compare/v10.0.3...v10.1.0) (2018-01-01) + + +### Bug Fixes + +* 'undefined' should be taken to mean no argument was provided ([#1015](https://github.com/yargs/yargs/issues/1015)) ([c679e90](https://github.com/yargs/yargs/commit/c679e90)) + + +### Features + +* add missing simple chinese locale strings ([#1004](https://github.com/yargs/yargs/issues/1004)) ([3cc24ec](https://github.com/yargs/yargs/commit/3cc24ec)) +* add Norwegian Nynorsk translations ([#1028](https://github.com/yargs/yargs/issues/1028)) ([a5ac213](https://github.com/yargs/yargs/commit/a5ac213)) +* async command handlers ([#1001](https://github.com/yargs/yargs/issues/1001)) ([241124b](https://github.com/yargs/yargs/commit/241124b)) +* middleware ([#881](https://github.com/yargs/yargs/issues/881)) ([77b8dbc](https://github.com/yargs/yargs/commit/77b8dbc)) + + + <a name="10.0.3"></a> ## [10.0.3](https://github.com/yargs/yargs/compare/v10.0.2...v10.0.3) (2017-10-21) diff --git a/node_modules/yargs/README.md b/node_modules/yargs/README.md index 84f8fea10..a09b32222 100644 --- a/node_modules/yargs/README.md +++ b/node_modules/yargs/README.md @@ -1,9 +1,11 @@ -# Yargs - -_Yargs is developed on evenings and weekends by -volunteers. Why not grab them dinner or a drink?_ - -[](https://gratipay.com/yargs/) +<p align="center"> + <img width="250" src="/yargs-logo.png"> +</p> +<h1 align="center"> Yargs </h1> +<p align="center"> + <b >Yargs be a node.js library fer hearties tryin' ter parse optstrings</b> +</p> +<br> [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] @@ -13,13 +15,10 @@ volunteers. Why not grab them dinner or a drink?_ [![Conventional Commits][conventional-commits-image]][conventional-commits-url] [![Slack][slack-image]][slack-url] -_Having problems? want to contribute? join our [community slack](http://devtoolscommunity.herokuapp.com)_. - -> Yargs be a node.js library fer hearties tryin' ter parse optstrings. - -<img width="250" src="/yargs-logo.png"> +## Description : +Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface. -Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface. It gives you: +It gives you: * commands and (grouped) options (`my-program.js serve --port=5000`). * a dynamically generated help menu based on your arguments. @@ -35,7 +34,9 @@ Yargs helps you build interactive command line tools, by parsing arguments and g npm i yargs --save ``` -## Simple Example +## Usage : + +### Simple Example ````javascript #!/usr/bin/env node @@ -56,9 +57,9 @@ $ ./plunder.js --ships 12 --distance 98.7 Retreat from the xupptumblers! ``` -## Complex Example +### Complex Example -```js +```javascript #!/usr/bin/env node require('yargs') // eslint-disable-line .command('serve [port]', 'start the server', (yargs) => { @@ -80,7 +81,13 @@ require('yargs') // eslint-disable-line Run the example above with `--help` to see the help for the application. -## Table of Contents +## Community : + +Having problems? want to contribute? join our [community slack](http://devtoolscommunity.herokuapp.com). + +## Documentation : + +### Table of Contents * [Yargs' API](/docs/api.md) * [Examples](/docs/examples.md) diff --git a/node_modules/yargs/lib/apply-extends.js b/node_modules/yargs/lib/apply-extends.js index 3005848e3..1436b6508 100644 --- a/node_modules/yargs/lib/apply-extends.js +++ b/node_modules/yargs/lib/apply-extends.js @@ -6,9 +6,9 @@ const YError = require('./yerror') let previouslyVisitedConfigs = [] -function checkForCircularExtends (path) { - if (previouslyVisitedConfigs.indexOf(path) > -1) { - throw new YError(`Circular extended configurations: '${path}'.`) +function checkForCircularExtends (cfgPath) { + if (previouslyVisitedConfigs.indexOf(cfgPath) > -1) { + throw new YError(`Circular extended configurations: '${cfgPath}'.`) } } @@ -21,7 +21,7 @@ function applyExtends (config, cwd) { if (config.hasOwnProperty('extends')) { if (typeof config.extends !== 'string') return defaultConfig - const isPath = /\.json$/.test(config.extends) + const isPath = /\.json|\..*rc$/.test(config.extends) let pathToDefault = null if (!isPath) { try { diff --git a/node_modules/yargs/lib/command.js b/node_modules/yargs/lib/command.js index 5ac848e21..65322dbbd 100644 --- a/node_modules/yargs/lib/command.js +++ b/node_modules/yargs/lib/command.js @@ -11,27 +11,26 @@ const DEFAULT_MARKER = /(^\*)|(^\$0)/ // arguments. module.exports = function command (yargs, usage, validation) { const self = {} - let handlers = {} let aliasMap = {} let defaultCommand - self.addHandler = function addHandler (cmd, description, builder, handler) { + self.addHandler = function addHandler (cmd, description, builder, handler, middlewares) { let aliases = [] handler = handler || (() => {}) - + middlewares = middlewares || [] if (Array.isArray(cmd)) { aliases = cmd.slice(1) cmd = cmd[0] } else if (typeof cmd === 'object') { let command = (Array.isArray(cmd.command) || typeof cmd.command === 'string') ? cmd.command : moduleName(cmd) if (cmd.aliases) command = [].concat(command).concat(cmd.aliases) - self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler) + self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares) return } // allow a module to be provided instead of separate builder and handler if (typeof builder === 'object' && builder.builder && typeof builder.handler === 'function') { - self.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler) + self.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler, builder.middlewares) return } @@ -50,6 +49,7 @@ module.exports = function command (yargs, usage, validation) { } return true }) + // standardize on $0 for default command. if (parsedAliases.length === 0 && isDefault) parsedAliases.push('$0') @@ -74,6 +74,7 @@ module.exports = function command (yargs, usage, validation) { description: description, handler, builder: builder || {}, + middlewares: middlewares || [], demanded: parsedCommand.demanded, optional: parsedCommand.optional } @@ -225,7 +226,19 @@ module.exports = function command (yargs, usage, validation) { if (commandHandler.handler && !yargs._hasOutput()) { yargs._setHasOutput() - commandHandler.handler(innerArgv) + 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) + ) + } } if (command) { diff --git a/node_modules/yargs/lib/usage.js b/node_modules/yargs/lib/usage.js index cf79b10de..c323c1bb1 100644 --- a/node_modules/yargs/lib/usage.js +++ b/node_modules/yargs/lib/usage.js @@ -46,9 +46,9 @@ module.exports = function usage (yargs, y18n) { if (!failureOutput) { failureOutput = true if (showHelpOnFail) yargs.showHelp('error') - if (msg) logger.error(msg) + if (msg || err) logger.error(msg || err) if (failMessage) { - if (msg) logger.error('') + if (msg || err) logger.error('') logger.error(failMessage) } } @@ -152,16 +152,23 @@ module.exports = function usage (yargs, y18n) { const demandedCommands = yargs.getDemandedCommands() const groups = yargs.getGroups() const options = yargs.getOptions() - let keys = Object.keys( - Object.keys(descriptions) - .concat(Object.keys(demandedOptions)) - .concat(Object.keys(demandedCommands)) - .concat(Object.keys(options.default)) - .reduce((acc, key) => { - if (key !== '_') acc[key] = true - return acc - }, {}) - ) + + let keys = [] + keys = keys.concat(Object.keys(descriptions)) + keys = keys.concat(Object.keys(demandedOptions)) + keys = keys.concat(Object.keys(demandedCommands)) + keys = keys.concat(Object.keys(options.default)) + keys = keys.filter(key => { + if (options.hiddenOptions.indexOf(key) < 0) { + return true + } else if (yargs.parsed.argv[options.showHiddenOpt]) { + return true + } + }) + keys = Object.keys(keys.reduce((acc, key) => { + if (key !== '_') acc[key] = true + return acc + }, {})) const theWrap = getWrap() const ui = require('cliui')({ diff --git a/node_modules/yargs/lib/validation.js b/node_modules/yargs/lib/validation.js index 1eee2fb02..f4655b4fd 100644 --- a/node_modules/yargs/lib/validation.js +++ b/node_modules/yargs/lib/validation.js @@ -54,38 +54,6 @@ module.exports = function validation (yargs, usage, y18n) { } } - // make sure that any args that require an - // value (--foo=bar), have a value. - self.missingArgumentValue = function missingArgumentValue (argv) { - const defaultValues = [true, false, ''] - const options = yargs.getOptions() - - if (options.requiresArg.length > 0) { - const missingRequiredArgs = [] - - options.requiresArg.forEach((key) => { - const value = argv[key] - - // if a value is explicitly requested, - // flag argument as missing if it does not - // look like foo=bar was entered. - if (~defaultValues.indexOf(value) || - (Array.isArray(value) && !value.length)) { - missingRequiredArgs.push(key) - } - }) - - if (missingRequiredArgs.length > 0) { - usage.fail(__n( - 'Missing argument value: %s', - 'Missing argument values: %s', - missingRequiredArgs.length, - missingRequiredArgs.join(', ') - )) - } - } - } - // make sure all the required arguments are present. self.requiredArguments = function requiredArguments (argv) { const demandedOptions = yargs.getDemandedOptions() diff --git a/node_modules/yargs/locales/zh_CN.json b/node_modules/yargs/locales/zh_CN.json index b25c7b9d2..03a3d94f0 100644 --- a/node_modules/yargs/locales/zh_CN.json +++ b/node_modules/yargs/locales/zh_CN.json @@ -33,5 +33,9 @@ "Invalid JSON config file: %s": "无效的 JSON 配置文件:%s", "Path to JSON config file": "JSON 配置文件的路径", "Show help": "显示帮助信息", - "Show version number": "显示版本号" + "Show version number": "显示版本号", + "Did you mean %s?": "是指 %s?", + "Arguments %s and %s are mutually exclusive" : "选项 %s 和 %s 是互斥的", + "Positionals:": "位置:", + "command": "命令" } diff --git a/node_modules/yargs/package.json b/node_modules/yargs/package.json index 56314fa3a..3ddba3725 100644 --- a/node_modules/yargs/package.json +++ b/node_modules/yargs/package.json @@ -1,6 +1,6 @@ { "name": "yargs", - "version": "10.0.3", + "version": "11.1.0", "description": "yargs the modern, pirate-themed, successor to optimist.", "main": "./index.js", "files": [ @@ -12,7 +12,7 @@ "LICENSE" ], "dependencies": { - "cliui": "^3.2.0", + "cliui": "^4.0.0", "decamelize": "^1.1.1", "find-up": "^2.1.0", "get-caller-file": "^1.0.1", @@ -23,14 +23,14 @@ "string-width": "^2.0.0", "which-module": "^2.0.0", "y18n": "^3.2.1", - "yargs-parser": "^8.0.0" + "yargs-parser": "^9.0.2" }, "devDependencies": { - "chai": "^3.4.1", + "chai": "^4.1.2", "chalk": "^1.1.3", "coveralls": "^2.11.11", "cpr": "^2.0.0", - "cross-spawn": "^5.0.1", + "cross-spawn": "^6.0.4", "es6-promise": "^4.0.2", "hashish": "0.0.4", "mocha": "^3.0.1", diff --git a/node_modules/yargs/yargs.js b/node_modules/yargs/yargs.js index 7f04ab451..d9d34a47c 100644 --- a/node_modules/yargs/yargs.js +++ b/node_modules/yargs/yargs.js @@ -92,8 +92,9 @@ function Yargs (processArgs, cwd, parentRequire) { groups = {} const arrayOptions = [ - 'array', 'boolean', 'string', 'requiresArg', 'skipValidation', - 'count', 'normalize', 'number' + 'array', 'boolean', 'string', 'skipValidation', + 'count', 'normalize', 'number', + 'hiddenOptions' ] const objectOptions = [ @@ -204,7 +205,7 @@ function Yargs (processArgs, cwd, parentRequire) { self.requiresArg = function (keys) { argsert('<array|string>', [keys], arguments.length) - populateParserHintArray('requiresArg', keys) + populateParserHintObject(self.nargs, false, 'narg', keys, 1) return self } @@ -338,9 +339,9 @@ function Yargs (processArgs, cwd, parentRequire) { return self } - self.command = function (cmd, description, builder, handler) { - argsert('<string|array|object> [string|boolean] [function|object] [function]', [cmd, description, builder, handler], arguments.length) - command.addHandler(cmd, description, builder, handler) + self.command = function (cmd, description, builder, handler, middlewares) { + argsert('<string|array|object> [string|boolean] [function|object] [function] [array]', [cmd, description, builder, handler, middlewares], arguments.length) + command.addHandler(cmd, description, builder, handler, middlewares) return self } @@ -476,17 +477,17 @@ function Yargs (processArgs, cwd, parentRequire) { return self } - self.pkgConf = function pkgConf (key, path) { - argsert('<string> [string]', [key, path], arguments.length) + self.pkgConf = function pkgConf (key, rootPath) { + argsert('<string> [string]', [key, rootPath], arguments.length) let conf = null // prefer cwd to require-main-filename in this method // since we're looking for e.g. "nyc" config in nyc consumer // rather than "yargs" config in nyc (where nyc is the main filename) - const obj = pkgUp(path || cwd) + const obj = pkgUp(rootPath || cwd) // If an object exists in the key, add it to options.configObjects if (obj[key] && typeof obj[key] === 'object') { - conf = applyExtends(obj[key], path || cwd) + conf = applyExtends(obj[key], rootPath || cwd) options.configObjects = (options.configObjects || []).concat(conf) } @@ -494,16 +495,24 @@ function Yargs (processArgs, cwd, parentRequire) { } const pkgs = {} - function pkgUp (path) { - const npath = path || '*' + function pkgUp (rootPath) { + const npath = rootPath || '*' if (pkgs[npath]) return pkgs[npath] const findUp = require('find-up') let obj = {} try { + let startDir = rootPath || require('require-main-filename')(parentRequire || require) + + // When called in an environment that lacks require.main.filename, such as a jest test runner, + // startDir is already process.cwd(), and should not be shortened. + // Whether or not it is _actually_ a directory (e.g., extensionless bin) is irrelevant, find-up handles it. + if (!rootPath && path.extname(startDir)) { + startDir = path.dirname(startDir) + } + const pkgJsonPath = findUp.sync('package.json', { - cwd: path || require('require-main-filename')(parentRequire || require), - normalize: false + cwd: startDir }) obj = JSON.parse(fs.readFileSync(pkgJsonPath)) } catch (noop) {} @@ -649,8 +658,9 @@ function Yargs (processArgs, cwd, parentRequire) { } const desc = opt.describe || opt.description || opt.desc - if (!opt.hidden) { - self.describe(key, desc) + self.describe(key, desc) + if (opt.hidden) { + self.hide(key) } if (opt.requiresArg) { @@ -816,6 +826,28 @@ function Yargs (processArgs, cwd, parentRequire) { return self } + const defaultShowHiddenOpt = 'show-hidden' + options.showHiddenOpt = defaultShowHiddenOpt + self.addShowHiddenOpt = self.showHidden = function addShowHiddenOpt (opt, msg) { + argsert('[string|boolean] [string]', [opt, msg], arguments.length) + + if (arguments.length === 1) { + if (opt === false) return self + } + + const showHiddenOpt = typeof opt === 'string' ? opt : defaultShowHiddenOpt + self.boolean(showHiddenOpt) + self.describe(showHiddenOpt, msg || usage.deferY18nLookup('Show hidden options')) + options.showHiddenOpt = showHiddenOpt + return self + } + + self.hide = function hide (key) { + argsert('<string|object>', [key], arguments.length) + options.hiddenOptions.push(key) + return self + } + self.showHelpOnFail = function showHelpOnFail (enabled, message) { argsert('[boolean|string] [string]', [enabled, message], arguments.length) usage.showHelpOnFail(enabled, message) @@ -964,6 +996,7 @@ function Yargs (processArgs, cwd, parentRequire) { options.__ = y18n.__ options.configuration = pkgUp()['yargs'] || {} + const parsed = Parser.detailed(args, options) let argv = parsed.argv if (parseContext) argv = Object.assign({}, argv, parseContext) @@ -1106,7 +1139,6 @@ function Yargs (processArgs, cwd, parentRequire) { self._runValidation = function runValidation (argv, aliases, positionalMap, parseErrors) { if (parseErrors) throw new YError(parseErrors.message) validation.nonOptionCount(argv) - validation.missingArgumentValue(argv) validation.requiredArguments(argv) if (strict) validation.unknownArguments(argv, aliases, positionalMap) validation.customChecks(argv, aliases) |