aboutsummaryrefslogtreecommitdiff
path: root/node_modules/yargs/yargs.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/yargs/yargs.js')
-rw-r--r--node_modules/yargs/yargs.js66
1 files changed, 49 insertions, 17 deletions
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)