aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/libnpx/node_modules/yargs/lib
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/libnpx/node_modules/yargs/lib')
-rw-r--r--deps/npm/node_modules/libnpx/node_modules/yargs/lib/apply-extends.js21
-rw-r--r--deps/npm/node_modules/libnpx/node_modules/yargs/lib/argsert.js30
-rw-r--r--deps/npm/node_modules/libnpx/node_modules/yargs/lib/assign.js15
-rw-r--r--deps/npm/node_modules/libnpx/node_modules/yargs/lib/command.js330
-rw-r--r--deps/npm/node_modules/libnpx/node_modules/yargs/lib/completion.js51
-rw-r--r--deps/npm/node_modules/libnpx/node_modules/yargs/lib/levenshtein.js10
-rw-r--r--deps/npm/node_modules/libnpx/node_modules/yargs/lib/obj-filter.js7
-rw-r--r--deps/npm/node_modules/libnpx/node_modules/yargs/lib/usage.js303
-rw-r--r--deps/npm/node_modules/libnpx/node_modules/yargs/lib/validation.js267
-rw-r--r--deps/npm/node_modules/libnpx/node_modules/yargs/lib/yerror.js1
10 files changed, 475 insertions, 560 deletions
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/apply-extends.js b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/apply-extends.js
index 3005848e3c..5fc69fab16 100644
--- a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/apply-extends.js
+++ b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/apply-extends.js
@@ -1,14 +1,13 @@
+var fs = require('fs')
+var path = require('path')
+var assign = require('./assign')
+var YError = require('./yerror')
-'use strict'
-const fs = require('fs')
-const path = require('path')
-const YError = require('./yerror')
-
-let previouslyVisitedConfigs = []
+var previouslyVisitedConfigs = []
function checkForCircularExtends (path) {
if (previouslyVisitedConfigs.indexOf(path) > -1) {
- throw new YError(`Circular extended configurations: '${path}'.`)
+ throw new YError("Circular extended configurations: '" + path + "'.")
}
}
@@ -17,12 +16,12 @@ function getPathToDefaultConfig (cwd, pathToExtend) {
}
function applyExtends (config, cwd) {
- let defaultConfig = {}
+ var defaultConfig = {}
if (config.hasOwnProperty('extends')) {
if (typeof config.extends !== 'string') return defaultConfig
- const isPath = /\.json$/.test(config.extends)
- let pathToDefault = null
+ var isPath = /\.json$/.test(config.extends)
+ var pathToDefault = null
if (!isPath) {
try {
pathToDefault = require.resolve(config.extends)
@@ -47,7 +46,7 @@ function applyExtends (config, cwd) {
previouslyVisitedConfigs = []
- return Object.assign({}, defaultConfig, config)
+ return assign(defaultConfig, config)
}
module.exports = applyExtends
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/argsert.js b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/argsert.js
index ed1d598713..d3e72fce57 100644
--- a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/argsert.js
+++ b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/argsert.js
@@ -1,21 +1,20 @@
-'use strict'
const command = require('./command')()
const YError = require('./yerror')
const positionName = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']
-module.exports = function argsert (expected, callerArguments, length) {
+module.exports = function (expected, callerArguments, length) {
// TODO: should this eventually raise an exception.
try {
// preface the argument description with "cmd", so
// that we can run it through yargs' command parser.
- let position = 0
- let parsed = {demanded: [], optional: []}
+ var position = 0
+ var parsed = {demanded: [], optional: []}
if (typeof expected === 'object') {
length = callerArguments
callerArguments = expected
} else {
- parsed = command.parseCommand(`cmd ${expected}`)
+ parsed = command.parseCommand('cmd ' + expected)
}
const args = [].slice.call(callerArguments)
@@ -23,27 +22,33 @@ module.exports = function argsert (expected, callerArguments, length) {
length = length || args.length
if (length < parsed.demanded.length) {
- throw new YError(`Not enough arguments provided. Expected ${parsed.demanded.length} but received ${args.length}.`)
+ throw new YError('Not enough arguments provided. Expected ' + parsed.demanded.length +
+ ' but received ' + args.length + '.')
}
const totalCommands = parsed.demanded.length + parsed.optional.length
if (length > totalCommands) {
- throw new YError(`Too many arguments provided. Expected max ${totalCommands} but received ${length}.`)
+ throw new YError('Too many arguments provided. Expected max ' + totalCommands +
+ ' but received ' + length + '.')
}
- parsed.demanded.forEach((demanded) => {
+ parsed.demanded.forEach(function (demanded) {
const arg = args.shift()
const observedType = guessType(arg)
- const matchingTypes = demanded.cmd.filter(type => type === observedType || type === '*')
+ const matchingTypes = demanded.cmd.filter(function (type) {
+ return type === observedType || type === '*'
+ })
if (matchingTypes.length === 0) argumentTypeError(observedType, demanded.cmd, position, false)
position += 1
})
- parsed.optional.forEach((optional) => {
+ parsed.optional.forEach(function (optional) {
if (args.length === 0) return
const arg = args.shift()
const observedType = guessType(arg)
- const matchingTypes = optional.cmd.filter(type => type === observedType || type === '*')
+ const matchingTypes = optional.cmd.filter(function (type) {
+ return type === observedType || type === '*'
+ })
if (matchingTypes.length === 0) argumentTypeError(observedType, optional.cmd, position, true)
position += 1
})
@@ -62,5 +67,6 @@ function guessType (arg) {
}
function argumentTypeError (observedType, allowedTypes, position, optional) {
- throw new YError(`Invalid ${positionName[position] || 'manyith'} argument. Expected ${allowedTypes.join(' or ')} but received ${observedType}.`)
+ throw new YError('Invalid ' + (positionName[position] || 'manyith') + ' argument.' +
+ ' Expected ' + allowedTypes.join(' or ') + ' but received ' + observedType + '.')
}
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/assign.js b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/assign.js
new file mode 100644
index 0000000000..7d5a3cef24
--- /dev/null
+++ b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/assign.js
@@ -0,0 +1,15 @@
+// lazy Object.assign logic that only works for merging
+// two objects; eventually we should replace this with Object.assign.
+module.exports = function assign (defaults, configuration) {
+ var o = {}
+ configuration = configuration || {}
+
+ Object.keys(defaults).forEach(function (k) {
+ o[k] = defaults[k]
+ })
+ Object.keys(configuration).forEach(function (k) {
+ o[k] = configuration[k]
+ })
+
+ return o
+}
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/command.js b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/command.js
index 65322dbbdb..3567cf9532 100644
--- a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/command.js
+++ b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/command.js
@@ -1,57 +1,67 @@
-'use strict'
-
-const inspect = require('util').inspect
const path = require('path')
-const Parser = require('yargs-parser')
+const inspect = require('util').inspect
+const camelCase = require('camelcase')
-const DEFAULT_MARKER = /(^\*)|(^\$0)/
+const DEFAULT_MARKER = '*'
// handles parsing positional arguments,
// and populating argv with said positional
// arguments.
-module.exports = function command (yargs, usage, validation) {
+module.exports = function (yargs, usage, validation) {
const self = {}
- let handlers = {}
- let aliasMap = {}
- let defaultCommand
- self.addHandler = function addHandler (cmd, description, builder, handler, middlewares) {
- let aliases = []
- handler = handler || (() => {})
- middlewares = middlewares || []
+
+ var handlers = {}
+ var aliasMap = {}
+ var defaultCommand
+ self.addHandler = function (cmd, description, builder, handler) {
+ var aliases = []
+ handler = handler || function () {}
+
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)
+ var 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, cmd.middlewares)
+ self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler)
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, builder.middlewares)
+ self.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler)
return
}
// parse positionals out of cmd string
- const parsedCommand = self.parseCommand(cmd)
+ var parsedCommand = self.parseCommand(cmd)
// remove positional args from aliases only
- aliases = aliases.map(alias => self.parseCommand(alias).cmd)
+ aliases = aliases.map(function (alias) {
+ return self.parseCommand(alias).cmd
+ })
// check for default and filter out '*''
- let isDefault = false
- const parsedAliases = [parsedCommand.cmd].concat(aliases).filter((c) => {
- if (DEFAULT_MARKER.test(c)) {
+ var isDefault = false
+ var parsedAliases = [parsedCommand.cmd].concat(aliases).filter(function (c) {
+ if (c === DEFAULT_MARKER) {
isDefault = true
return false
}
return true
})
- // standardize on $0 for default command.
- if (parsedAliases.length === 0 && isDefault) parsedAliases.push('$0')
+ // short-circuit if default with no aliases
+ if (isDefault && parsedAliases.length === 0) {
+ defaultCommand = {
+ original: cmd.replace(DEFAULT_MARKER, '').trim(),
+ handler: handler,
+ builder: builder || {},
+ demanded: parsedCommand.demanded,
+ optional: parsedCommand.optional
+ }
+ return
+ }
// shift cmd and aliases after filtering out '*'
if (isDefault) {
@@ -61,7 +71,7 @@ module.exports = function command (yargs, usage, validation) {
}
// populate aliasMap
- aliases.forEach((alias) => {
+ aliases.forEach(function (alias) {
aliasMap[alias] = parsedCommand.cmd
})
@@ -71,10 +81,8 @@ module.exports = function command (yargs, usage, validation) {
handlers[parsedCommand.cmd] = {
original: cmd,
- description: description,
- handler,
+ handler: handler,
builder: builder || {},
- middlewares: middlewares || [],
demanded: parsedCommand.demanded,
optional: parsedCommand.optional
}
@@ -82,16 +90,16 @@ module.exports = function command (yargs, usage, validation) {
if (isDefault) defaultCommand = handlers[parsedCommand.cmd]
}
- self.addDirectory = function addDirectory (dir, context, req, callerFile, opts) {
+ self.addDirectory = function (dir, context, req, callerFile, opts) {
opts = opts || {}
// disable recursion to support nested directories of subcommands
if (typeof opts.recurse !== 'boolean') opts.recurse = false
// exclude 'json', 'coffee' from require-directory defaults
if (!Array.isArray(opts.extensions)) opts.extensions = ['js']
// allow consumer to define their own visitor function
- const parentVisit = typeof opts.visit === 'function' ? opts.visit : o => o
+ const parentVisit = typeof opts.visit === 'function' ? opts.visit : function (o) { return o }
// call addHandler via visitor function
- opts.visit = function visit (obj, joined, filename) {
+ opts.visit = function (obj, joined, filename) {
const visited = parentVisit(obj, joined, filename)
// allow consumer to skip modules with their own visitor
if (visited) {
@@ -111,7 +119,7 @@ module.exports = function command (yargs, usage, validation) {
// if module was not require()d and no name given, throw error
function moduleName (obj) {
const mod = require('which-module')(obj)
- if (!mod) throw new Error(`No command name given for module: ${inspect(obj)}`)
+ if (!mod) throw new Error('No command name given for module: ' + inspect(obj))
return commandFromFilename(mod.filename)
}
@@ -121,62 +129,66 @@ module.exports = function command (yargs, usage, validation) {
}
function extractDesc (obj) {
- for (let keys = ['describe', 'description', 'desc'], i = 0, l = keys.length, test; i < l; i++) {
+ for (var keys = ['describe', 'description', 'desc'], i = 0, l = keys.length, test; i < l; i++) {
test = obj[keys[i]]
if (typeof test === 'string' || typeof test === 'boolean') return test
}
return false
}
- self.parseCommand = function parseCommand (cmd) {
- const extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' ')
- const splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/)
- const bregex = /\.*[\][<>]/g
- const parsedCommand = {
+ self.parseCommand = function (cmd) {
+ var extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' ')
+ var splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/)
+ var bregex = /\.*[\][<>]/g
+ var parsedCommand = {
cmd: (splitCommand.shift()).replace(bregex, ''),
demanded: [],
optional: []
}
- splitCommand.forEach((cmd, i) => {
- let variadic = false
+ splitCommand.forEach(function (cmd, i) {
+ var variadic = false
cmd = cmd.replace(/\s/g, '')
if (/\.+[\]>]/.test(cmd) && i === splitCommand.length - 1) variadic = true
if (/^\[/.test(cmd)) {
parsedCommand.optional.push({
cmd: cmd.replace(bregex, '').split('|'),
- variadic
+ variadic: variadic
})
} else {
parsedCommand.demanded.push({
cmd: cmd.replace(bregex, '').split('|'),
- variadic
+ variadic: variadic
})
}
})
return parsedCommand
}
- self.getCommands = () => Object.keys(handlers).concat(Object.keys(aliasMap))
+ self.getCommands = function () {
+ return Object.keys(handlers).concat(Object.keys(aliasMap))
+ }
- self.getCommandHandlers = () => handlers
+ self.getCommandHandlers = function () {
+ return handlers
+ }
- self.hasDefaultCommand = () => !!defaultCommand
+ self.hasDefaultCommand = function () {
+ return !!defaultCommand
+ }
- self.runCommand = function runCommand (command, yargs, parsed, commandIndex) {
- let aliases = parsed.aliases
- const commandHandler = handlers[command] || handlers[aliasMap[command]] || defaultCommand
- const currentContext = yargs.getContext()
- let numFiles = currentContext.files.length
- const parentCommands = currentContext.commands.slice()
+ self.runCommand = function (command, yargs, parsed, commandIndex) {
+ var aliases = parsed.aliases
+ var commandHandler = handlers[command] || handlers[aliasMap[command]] || defaultCommand
+ var currentContext = yargs.getContext()
+ var numFiles = currentContext.files.length
+ var parentCommands = currentContext.commands.slice()
// what does yargs look like after the buidler is run?
- let innerArgv = parsed.argv
- let innerYargs = null
- let positionalMap = {}
- if (command) {
- currentContext.commands.push(command)
- currentContext.fullCommands.push(commandHandler.original)
- }
+ var innerArgv = parsed.argv
+ var innerYargs = null
+ var positionalMap = {}
+
+ if (command) currentContext.commands.push(command)
if (typeof commandHandler.builder === 'function') {
// a function can be provided, which builds
// up a yargs chain and possibly returns it.
@@ -186,11 +198,8 @@ module.exports = function command (yargs, usage, validation) {
// original command string as usage() for consistent behavior with
// options object below.
if (yargs.parsed === false) {
- if (shouldUpdateUsage(yargs)) {
- yargs.getUsageInstance().usage(
- usageFromParentCommandsCommandHandler(parentCommands, commandHandler),
- commandHandler.description
- )
+ if (typeof yargs.getUsageInstance().getUsage() === 'undefined') {
+ yargs.usage('$0 ' + (parentCommands.length ? parentCommands.join(' ') + ' ' : '') + commandHandler.original)
}
innerArgv = innerYargs ? innerYargs._parseArgs(null, null, true, commandIndex) : yargs._parseArgs(null, null, true, commandIndex)
} else {
@@ -203,13 +212,8 @@ module.exports = function command (yargs, usage, validation) {
// as a short hand, an object can instead be provided, specifying
// the options that a command takes.
innerYargs = yargs.reset(parsed.aliases)
- if (shouldUpdateUsage(innerYargs)) {
- innerYargs.getUsageInstance().usage(
- usageFromParentCommandsCommandHandler(parentCommands, commandHandler),
- commandHandler.description
- )
- }
- Object.keys(commandHandler.builder).forEach((key) => {
+ innerYargs.usage('$0 ' + (parentCommands.length ? parentCommands.join(' ') + ' ' : '') + commandHandler.original)
+ Object.keys(commandHandler.builder).forEach(function (key) {
innerYargs.option(key, commandHandler.builder[key])
})
innerArgv = innerYargs._parseArgs(null, null, true, commandIndex)
@@ -226,178 +230,84 @@ module.exports = function command (yargs, usage, validation) {
if (commandHandler.handler && !yargs._hasOutput()) {
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)
- )
- }
+ commandHandler.handler(innerArgv)
}
- if (command) {
- currentContext.commands.pop()
- currentContext.fullCommands.pop()
- }
+ if (command) currentContext.commands.pop()
numFiles = currentContext.files.length - numFiles
if (numFiles > 0) currentContext.files.splice(numFiles * -1, numFiles)
return innerArgv
}
- function shouldUpdateUsage (yargs) {
- return !yargs.getUsageInstance().getUsageDisabled() &&
- yargs.getUsageInstance().getUsage().length === 0
- }
-
- function usageFromParentCommandsCommandHandler (parentCommands, commandHandler) {
- const c = DEFAULT_MARKER.test(commandHandler.original) ? commandHandler.original.replace(DEFAULT_MARKER, '').trim() : commandHandler.original
- const pc = parentCommands.filter((c) => { return !DEFAULT_MARKER.test(c) })
- pc.push(c)
- return `$0 ${pc.join(' ')}`
- }
-
- self.runDefaultBuilderOn = function (yargs) {
- if (shouldUpdateUsage(yargs)) {
- // build the root-level command string from the default string.
- const commandString = DEFAULT_MARKER.test(defaultCommand.original)
- ? defaultCommand.original : defaultCommand.original.replace(/^[^[\]<>]*/, '$0 ')
- yargs.getUsageInstance().usage(
- commandString,
- defaultCommand.description
- )
- }
- const builder = defaultCommand.builder
- if (typeof builder === 'function') {
- builder(yargs)
- } else {
- Object.keys(builder).forEach((key) => {
- yargs.option(key, builder[key])
- })
- }
- }
-
// transcribe all positional arguments "command <foo> <bar> [apple]"
// onto argv.
function populatePositionals (commandHandler, argv, context, yargs) {
argv._ = argv._.slice(context.commands.length) // nuke the current commands
- const demanded = commandHandler.demanded.slice(0)
- const optional = commandHandler.optional.slice(0)
- const positionalMap = {}
+ var demanded = commandHandler.demanded.slice(0)
+ var optional = commandHandler.optional.slice(0)
+ var positionalMap = {}
validation.positionalCount(demanded.length, argv._.length)
while (demanded.length) {
- const demand = demanded.shift()
- populatePositional(demand, argv, positionalMap)
+ var demand = demanded.shift()
+ populatePositional(demand, argv, yargs, positionalMap)
}
while (optional.length) {
- const maybe = optional.shift()
- populatePositional(maybe, argv, positionalMap)
+ var maybe = optional.shift()
+ populatePositional(maybe, argv, yargs, positionalMap)
}
argv._ = context.commands.concat(argv._)
-
- postProcessPositionals(argv, positionalMap, self.cmdToParseOptions(commandHandler.original))
-
return positionalMap
}
- function populatePositional (positional, argv, positionalMap, parseOptions) {
- const cmd = positional.cmd[0]
- if (positional.variadic) {
- positionalMap[cmd] = argv._.splice(0).map(String)
- } else {
- if (argv._.length) positionalMap[cmd] = [String(argv._.shift())]
+ // populate a single positional argument and its
+ // aliases onto argv.
+ function populatePositional (positional, argv, yargs, positionalMap) {
+ // "positional" consists of the positional.cmd, an array representing
+ // the positional's name and aliases, and positional.variadic
+ // indicating whether or not it is a variadic array.
+ var variadics = null
+ var value = null
+ for (var i = 0, cmd; (cmd = positional.cmd[i]) !== undefined; i++) {
+ if (positional.variadic) {
+ if (variadics) argv[cmd] = variadics.slice(0)
+ else argv[cmd] = variadics = argv._.splice(0)
+ } else {
+ if (!value && !argv._.length) continue
+ if (value) argv[cmd] = value
+ else argv[cmd] = value = argv._.shift()
+ }
+ positionalMap[cmd] = true
+ postProcessPositional(yargs, argv, cmd)
+ addCamelCaseExpansions(argv, cmd)
}
}
- // we run yargs-parser against the positional arguments
- // applying the same parsing logic used for flags.
- function postProcessPositionals (argv, positionalMap, parseOptions) {
- // combine the parsing hints we've inferred from the command
- // string with explicitly configured parsing hints.
- const options = Object.assign({}, yargs.getOptions())
- options.default = Object.assign(parseOptions.default, options.default)
- options.alias = Object.assign(parseOptions.alias, options.alias)
- options.array = options.array.concat(parseOptions.array)
-
- const unparsed = []
- Object.keys(positionalMap).forEach((key) => {
- positionalMap[key].map((value) => {
- unparsed.push(`--${key}`)
- unparsed.push(value)
- })
- })
-
- // short-circuit parse.
- if (!unparsed.length) return
-
- const parsed = Parser.detailed(unparsed, options)
-
- if (parsed.error) {
- yargs.getUsageInstance().fail(parsed.error.message, parsed.error)
- } else {
- // only copy over positional keys (don't overwrite
- // flag arguments that were already parsed).
- const positionalKeys = Object.keys(positionalMap)
- Object.keys(positionalMap).forEach((key) => {
- [].push.apply(positionalKeys, parsed.aliases[key])
- })
-
- Object.keys(parsed.argv).forEach((key) => {
- if (positionalKeys.indexOf(key) !== -1) {
- argv[key] = parsed.argv[key]
- }
- })
+ // TODO move positional arg logic to yargs-parser and remove this duplication
+ function postProcessPositional (yargs, argv, key) {
+ var coerce = yargs.getOptions().coerce[key]
+ if (typeof coerce === 'function') {
+ try {
+ argv[key] = coerce(argv[key])
+ } catch (err) {
+ yargs.getUsageInstance().fail(err.message, err)
+ }
}
}
- self.cmdToParseOptions = function (cmdString) {
- const parseOptions = {
- array: [],
- default: {},
- alias: {},
- demand: {}
+ function addCamelCaseExpansions (argv, option) {
+ if (/-/.test(option)) {
+ const cc = camelCase(option)
+ if (typeof argv[option] === 'object') argv[cc] = argv[option].slice(0)
+ else argv[cc] = argv[option]
}
-
- const parsed = self.parseCommand(cmdString)
- parsed.demanded.forEach((d) => {
- const cmds = d.cmd.slice(0)
- const cmd = cmds.shift()
- if (d.variadic) {
- parseOptions.array.push(cmd)
- parseOptions.default[cmd] = []
- }
- cmds.forEach((c) => {
- parseOptions.alias[cmd] = c
- })
- parseOptions.demand[cmd] = true
- })
-
- parsed.optional.forEach((o) => {
- const cmds = o.cmd.slice(0)
- const cmd = cmds.shift()
- if (o.variadic) {
- parseOptions.array.push(cmd)
- parseOptions.default[cmd] = []
- }
- cmds.forEach((c) => {
- parseOptions.alias[cmd] = c
- })
- })
-
- return parseOptions
}
- self.reset = () => {
+ self.reset = function () {
handlers = {}
aliasMap = {}
defaultCommand = undefined
@@ -408,14 +318,14 @@ module.exports = function command (yargs, usage, validation) {
// the state of commands such that
// we can apply .parse() multiple times
// with the same yargs instance.
- let frozen
- self.freeze = () => {
+ var frozen
+ self.freeze = function () {
frozen = {}
frozen.handlers = handlers
frozen.aliasMap = aliasMap
frozen.defaultCommand = defaultCommand
}
- self.unfreeze = () => {
+ self.unfreeze = function () {
handlers = frozen.handlers
aliasMap = frozen.aliasMap
defaultCommand = frozen.defaultCommand
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/completion.js b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/completion.js
index ad6969a2d9..5cd9a18a03 100644
--- a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/completion.js
+++ b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/completion.js
@@ -1,17 +1,16 @@
-'use strict'
const fs = require('fs')
const path = require('path')
// add bash completions to your
// yargs-powered applications.
-module.exports = function completion (yargs, usage, command) {
+module.exports = function (yargs, usage, command) {
const self = {
completionKey: 'get-yargs-completions'
}
// get a list of completion commands.
// 'args' is the array of strings from the line to be completed
- self.getCompletion = function getCompletion (args, done) {
+ self.getCompletion = function (args, done) {
const completions = []
const current = args.length ? args[args.length - 1] : ''
const argv = yargs.parse(args, true)
@@ -21,14 +20,14 @@ module.exports = function completion (yargs, usage, command) {
// to completion().
if (completionFunction) {
if (completionFunction.length < 3) {
- const result = completionFunction(current, argv)
+ var result = completionFunction(current, argv)
// promise based completion function.
if (typeof result.then === 'function') {
- return result.then((list) => {
- process.nextTick(() => { done(list) })
- }).catch((err) => {
- process.nextTick(() => { throw err })
+ return result.then(function (list) {
+ process.nextTick(function () { done(list) })
+ }).catch(function (err) {
+ process.nextTick(function () { throw err })
})
}
@@ -36,14 +35,14 @@ module.exports = function completion (yargs, usage, command) {
return done(result)
} else {
// asynchronous completion function
- return completionFunction(current, argv, (completions) => {
+ return completionFunction(current, argv, function (completions) {
done(completions)
})
}
}
- const handlers = command.getCommandHandlers()
- for (let i = 0, ii = args.length; i < ii; ++i) {
+ var handlers = command.getCommandHandlers()
+ for (var i = 0, ii = args.length; i < ii; ++i) {
if (handlers[args[i]] && handlers[args[i]].builder) {
const builder = handlers[args[i]].builder
if (typeof builder === 'function') {
@@ -55,21 +54,22 @@ module.exports = function completion (yargs, usage, command) {
}
if (!current.match(/^-/)) {
- usage.getCommands().forEach((usageCommand) => {
- const commandName = command.parseCommand(usageCommand[0]).cmd
- if (args.indexOf(commandName) === -1) {
- completions.push(commandName)
+ usage.getCommands().forEach(function (command) {
+ if (args.indexOf(command[0]) === -1) {
+ completions.push(command[0])
}
})
}
if (current.match(/^-/)) {
- Object.keys(yargs.getOptions().key).forEach((key) => {
+ Object.keys(yargs.getOptions().key).forEach(function (key) {
// If the key and its aliases aren't in 'args', add the key to 'completions'
- const keyAndAliases = [key].concat(aliases[key] || [])
- const notInArgs = keyAndAliases.every(val => args.indexOf(`--${val}`) === -1)
+ var keyAndAliases = [key].concat(aliases[key] || [])
+ var notInArgs = keyAndAliases.every(function (val) {
+ return args.indexOf('--' + val) === -1
+ })
if (notInArgs) {
- completions.push(`--${key}`)
+ completions.push('--' + key)
}
})
}
@@ -78,26 +78,25 @@ module.exports = function completion (yargs, usage, command) {
}
// generate the completion script to add to your .bashrc.
- self.generateCompletionScript = function generateCompletionScript ($0, cmd) {
- let script = fs.readFileSync(
+ self.generateCompletionScript = function ($0) {
+ var script = fs.readFileSync(
path.resolve(__dirname, '../completion.sh.hbs'),
'utf-8'
)
- const name = path.basename($0)
+ var name = path.basename($0)
// add ./to applications not yet installed as bin.
- if ($0.match(/\.js$/)) $0 = `./${$0}`
+ if ($0.match(/\.js$/)) $0 = './' + $0
script = script.replace(/{{app_name}}/g, name)
- script = script.replace(/{{completion_command}}/g, cmd)
return script.replace(/{{app_path}}/g, $0)
}
// register a function to perform your own custom
// completions., this function can be either
// synchrnous or asynchronous.
- let completionFunction = null
- self.registerFunction = (fn) => {
+ var completionFunction = null
+ self.registerFunction = function (fn) {
completionFunction = fn
}
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/levenshtein.js b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/levenshtein.js
index f32b0c2771..6ec216f59d 100644
--- a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/levenshtein.js
+++ b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/levenshtein.js
@@ -10,22 +10,22 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
// levenshtein distance algorithm, pulled from Andrei Mackenzie's MIT licensed.
// gist, which can be found here: https://gist.github.com/andrei-m/982927
-'use strict'
+
// Compute the edit distance between the two given strings
-module.exports = function levenshtein (a, b) {
+module.exports = function (a, b) {
if (a.length === 0) return b.length
if (b.length === 0) return a.length
- const matrix = []
+ var matrix = []
// increment along the first column of each row
- let i
+ var i
for (i = 0; i <= b.length; i++) {
matrix[i] = [i]
}
// increment each column in the first row
- let j
+ var j
for (j = 0; j <= a.length; j++) {
matrix[0][j] = j
}
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/obj-filter.js b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/obj-filter.js
index c344ac58ca..42cb9961ee 100644
--- a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/obj-filter.js
+++ b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/obj-filter.js
@@ -1,8 +1,7 @@
-'use strict'
-module.exports = function objFilter (original, filter) {
+module.exports = function (original, filter) {
const obj = {}
- filter = filter || ((k, v) => true)
- Object.keys(original || {}).forEach((key) => {
+ filter = filter || function (k, v) { return true }
+ Object.keys(original || {}).forEach(function (key) {
if (filter(key, original[key])) {
obj[key] = original[key]
}
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/usage.js b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/usage.js
index bd0906a89d..43f71225c3 100644
--- a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/usage.js
+++ b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/usage.js
@@ -1,25 +1,23 @@
-'use strict'
// this file handles outputting usage instructions,
// failures, etc. keeps logging in one place.
const stringWidth = require('string-width')
const objFilter = require('./obj-filter')
-const path = require('path')
const setBlocking = require('set-blocking')
const YError = require('./yerror')
-module.exports = function usage (yargs, y18n) {
+module.exports = function (yargs, y18n) {
const __ = y18n.__
const self = {}
// methods for ouputting/building failure message.
- const fails = []
- self.failFn = function failFn (f) {
+ var fails = []
+ self.failFn = function (f) {
fails.push(f)
}
- let failMessage = null
- let showHelpOnFail = true
- self.showHelpOnFail = function showHelpOnFailFn (enabled, message) {
+ var failMessage = null
+ var showHelpOnFail = true
+ self.showHelpOnFail = function (enabled, message) {
if (typeof enabled === 'string') {
message = enabled
enabled = true
@@ -31,12 +29,12 @@ module.exports = function usage (yargs, y18n) {
return self
}
- let failureOutput = false
- self.fail = function fail (msg, err) {
+ var failureOutput = false
+ self.fail = function (msg, err) {
const logger = yargs._getLoggerInstance()
if (fails.length) {
- for (let i = fails.length - 1; i >= 0; --i) {
+ for (var i = fails.length - 1; i >= 0; --i) {
fails[i](msg, err, self)
}
} else {
@@ -46,9 +44,9 @@ module.exports = function usage (yargs, y18n) {
if (!failureOutput) {
failureOutput = true
if (showHelpOnFail) yargs.showHelp('error')
- if (msg || err) logger.error(msg || err)
+ if (msg) logger.error(msg)
if (failMessage) {
- if (msg || err) logger.error('')
+ if (msg) logger.error('')
logger.error(failMessage)
}
}
@@ -65,67 +63,56 @@ module.exports = function usage (yargs, y18n) {
}
// methods for ouputting/building help (usage) message.
- let usages = []
- let usageDisabled = false
- self.usage = (msg, description) => {
- if (msg === null) {
- usageDisabled = true
- usages = []
- return
- }
- usageDisabled = false
- usages.push([msg, description || ''])
- return self
- }
- self.getUsage = () => {
- return usages
+ var usage
+ self.usage = function (msg) {
+ usage = msg
}
- self.getUsageDisabled = () => {
- return usageDisabled
- }
-
- self.getPositionalGroupName = () => {
- return __('Positionals:')
+ self.getUsage = function () {
+ return usage
}
- let examples = []
- self.example = (cmd, description) => {
+ var examples = []
+ self.example = function (cmd, description) {
examples.push([cmd, description || ''])
}
- let commands = []
- self.command = function command (cmd, description, isDefault, aliases) {
+ var commands = []
+ self.command = function (cmd, description, isDefault, aliases) {
// the last default wins, so cancel out any previously set default
if (isDefault) {
- commands = commands.map((cmdArray) => {
+ commands = commands.map(function (cmdArray) {
cmdArray[2] = false
return cmdArray
})
}
commands.push([cmd, description || '', isDefault, aliases])
}
- self.getCommands = () => commands
+ self.getCommands = function () {
+ return commands
+ }
- let descriptions = {}
- self.describe = function describe (key, desc) {
+ var descriptions = {}
+ self.describe = function (key, desc) {
if (typeof key === 'object') {
- Object.keys(key).forEach((k) => {
+ Object.keys(key).forEach(function (k) {
self.describe(k, key[k])
})
} else {
descriptions[key] = desc
}
}
- self.getDescriptions = () => descriptions
+ self.getDescriptions = function () {
+ return descriptions
+ }
- let epilog
- self.epilog = (msg) => {
+ var epilog
+ self.epilog = function (msg) {
epilog = msg
}
- let wrapSet = false
- let wrap
- self.wrap = (cols) => {
+ var wrapSet = false
+ var wrap
+ self.wrap = function (cols) {
wrapSet = true
wrap = cols
}
@@ -139,57 +126,41 @@ module.exports = function usage (yargs, y18n) {
return wrap
}
- const deferY18nLookupPrefix = '__yargsString__:'
- self.deferY18nLookup = str => deferY18nLookupPrefix + str
+ var deferY18nLookupPrefix = '__yargsString__:'
+ self.deferY18nLookup = function (str) {
+ return deferY18nLookupPrefix + str
+ }
- const defaultGroup = 'Options:'
- self.help = function help () {
+ var defaultGroup = 'Options:'
+ self.help = function () {
normalizeAliases()
// handle old demanded API
- const base$0 = path.basename(yargs.$0)
- const demandedOptions = yargs.getDemandedOptions()
- const demandedCommands = yargs.getDemandedCommands()
- const groups = yargs.getGroups()
- const options = yargs.getOptions()
- let keys = Object.keys(
+ var demandedOptions = yargs.getDemandedOptions()
+ var demandedCommands = yargs.getDemandedCommands()
+ var groups = yargs.getGroups()
+ var options = yargs.getOptions()
+ var keys = Object.keys(
Object.keys(descriptions)
.concat(Object.keys(demandedOptions))
.concat(Object.keys(demandedCommands))
.concat(Object.keys(options.default))
- .reduce((acc, key) => {
+ .reduce(function (acc, key) {
if (key !== '_') acc[key] = true
return acc
}, {})
)
- const theWrap = getWrap()
- const ui = require('cliui')({
+ var theWrap = getWrap()
+ var ui = require('cliui')({
width: theWrap,
wrap: !!theWrap
})
// the usage string.
- if (!usageDisabled) {
- if (usages.length) {
- // user-defined usage.
- usages.forEach((usage) => {
- ui.div(`${usage[0].replace(/\$0/g, base$0)}`)
- if (usage[1]) {
- ui.div({text: `${usage[1]}`, padding: [1, 0, 0, 0]})
- }
- })
- ui.div()
- } else if (commands.length) {
- let u = null
- // demonstrate how commands are used.
- if (demandedCommands._) {
- u = `${base$0} <${__('command')}>\n`
- } else {
- u = `${base$0} [${__('command')}]\n`
- }
- ui.div(`${u}`)
- }
+ if (usage) {
+ var u = usage.replace(/\$0/g, yargs.$0)
+ ui.div(u + '\n')
}
// your application's commands, i.e., non-option
@@ -197,23 +168,15 @@ module.exports = function usage (yargs, y18n) {
if (commands.length) {
ui.div(__('Commands:'))
- const context = yargs.getContext()
- const parentCommands = context.commands.length ? `${context.commands.join(' ')} ` : ''
-
- commands.forEach((command) => {
- const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}` // drop $0 from default commands.
+ commands.forEach(function (command) {
ui.span(
- {
- text: commandString,
- padding: [0, 2, 0, 2],
- width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4
- },
+ {text: command[0], padding: [0, 2, 0, 2], width: maxWidth(commands, theWrap) + 4},
{text: command[1]}
)
- const hints = []
- if (command[2]) hints.push(`[${__('default:').slice(0, -1)}]`) // TODO hacking around i18n here
+ var hints = []
+ if (command[2]) hints.push('[' + __('default:').slice(0, -1) + ']') // TODO hacking around i18n here
if (command[3] && command[3].length) {
- hints.push(`[${__('aliases:')} ${command[3].join(', ')}]`)
+ hints.push('[' + __('aliases:') + ' ' + command[3].join(', ') + ']')
}
if (hints.length) {
ui.div({text: hints.join(' '), padding: [0, 0, 0, 2], align: 'right'})
@@ -227,10 +190,14 @@ module.exports = function usage (yargs, y18n) {
// perform some cleanup on the keys array, making it
// only include top-level keys not their aliases.
- const aliasKeys = (Object.keys(options.alias) || [])
+ var aliasKeys = (Object.keys(options.alias) || [])
.concat(Object.keys(yargs.parsed.newAliases) || [])
- keys = keys.filter(key => !yargs.parsed.newAliases[key] && aliasKeys.every(alias => (options.alias[alias] || []).indexOf(key) === -1))
+ keys = keys.filter(function (key) {
+ return !yargs.parsed.newAliases[key] && aliasKeys.every(function (alias) {
+ return (options.alias[alias] || []).indexOf(key) === -1
+ })
+ })
// populate 'Options:' group with any keys that have not
// explicitly had a group set.
@@ -238,54 +205,51 @@ module.exports = function usage (yargs, y18n) {
addUngroupedKeys(keys, options.alias, groups)
// display 'Options:' table along with any custom tables:
- Object.keys(groups).forEach((groupName) => {
+ Object.keys(groups).forEach(function (groupName) {
if (!groups[groupName].length) return
ui.div(__(groupName))
// if we've grouped the key 'f', but 'f' aliases 'foobar',
// normalizedKeys should contain only 'foobar'.
- const normalizedKeys = groups[groupName].map((key) => {
+ var normalizedKeys = groups[groupName].map(function (key) {
if (~aliasKeys.indexOf(key)) return key
- for (let i = 0, aliasKey; (aliasKey = aliasKeys[i]) !== undefined; i++) {
+ for (var i = 0, aliasKey; (aliasKey = aliasKeys[i]) !== undefined; i++) {
if (~(options.alias[aliasKey] || []).indexOf(key)) return aliasKey
}
return key
})
// actually generate the switches string --foo, -f, --bar.
- const switches = normalizedKeys.reduce((acc, key) => {
+ var switches = normalizedKeys.reduce(function (acc, key) {
acc[key] = [ key ].concat(options.alias[key] || [])
- .map(sw => {
- // for the special positional group don't
- // add '--' or '-' prefix.
- if (groupName === self.getPositionalGroupName()) return sw
- else return (sw.length > 1 ? '--' : '-') + sw
+ .map(function (sw) {
+ return (sw.length > 1 ? '--' : '-') + sw
})
.join(', ')
return acc
}, {})
- normalizedKeys.forEach((key) => {
- const kswitch = switches[key]
- let desc = descriptions[key] || ''
- let type = null
+ normalizedKeys.forEach(function (key) {
+ var kswitch = switches[key]
+ var desc = descriptions[key] || ''
+ var type = null
if (~desc.lastIndexOf(deferY18nLookupPrefix)) desc = __(desc.substring(deferY18nLookupPrefix.length))
- if (~options.boolean.indexOf(key)) type = `[${__('boolean')}]`
- if (~options.count.indexOf(key)) type = `[${__('count')}]`
- if (~options.string.indexOf(key)) type = `[${__('string')}]`
- if (~options.normalize.indexOf(key)) type = `[${__('string')}]`
- if (~options.array.indexOf(key)) type = `[${__('array')}]`
- if (~options.number.indexOf(key)) type = `[${__('number')}]`
+ if (~options.boolean.indexOf(key)) type = '[' + __('boolean') + ']'
+ if (~options.count.indexOf(key)) type = '[' + __('count') + ']'
+ if (~options.string.indexOf(key)) type = '[' + __('string') + ']'
+ if (~options.normalize.indexOf(key)) type = '[' + __('string') + ']'
+ if (~options.array.indexOf(key)) type = '[' + __('array') + ']'
+ if (~options.number.indexOf(key)) type = '[' + __('number') + ']'
- const extra = [
+ var extra = [
type,
- (key in demandedOptions) ? `[${__('required')}]` : null,
- options.choices && options.choices[key] ? `[${__('choices:')} ${
- self.stringifiedValues(options.choices[key])}]` : null,
+ (key in demandedOptions) ? '[' + __('required') + ']' : null,
+ options.choices && options.choices[key] ? '[' + __('choices:') + ' ' +
+ self.stringifiedValues(options.choices[key]) + ']' : null,
defaultString(options.default[key], options.defaultDescription[key])
].filter(Boolean).join(' ')
@@ -305,11 +269,11 @@ module.exports = function usage (yargs, y18n) {
if (examples.length) {
ui.div(__('Examples:'))
- examples.forEach((example) => {
- example[0] = example[0].replace(/\$0/g, base$0)
+ examples.forEach(function (example) {
+ example[0] = example[0].replace(/\$0/g, yargs.$0)
})
- examples.forEach((example) => {
+ examples.forEach(function (example) {
if (example[1] === '') {
ui.div(
{
@@ -335,8 +299,8 @@ module.exports = function usage (yargs, y18n) {
// the usage string.
if (epilog) {
- const e = epilog.replace(/\$0/g, base$0)
- ui.div(`${e}\n`)
+ var e = epilog.replace(/\$0/g, yargs.$0)
+ ui.div(e + '\n')
}
return ui.toString()
@@ -344,20 +308,19 @@ module.exports = function usage (yargs, y18n) {
// return the maximum width of a string
// in the left-hand column of a table.
- function maxWidth (table, theWrap, modifier) {
- let width = 0
+ function maxWidth (table, theWrap) {
+ var width = 0
// table might be of the form [leftColumn],
// or {key: leftColumn}
if (!Array.isArray(table)) {
- table = Object.keys(table).map(key => [table[key]])
+ table = Object.keys(table).map(function (key) {
+ return [table[key]]
+ })
}
- table.forEach((v) => {
- width = Math.max(
- stringWidth(modifier ? `${modifier} ${v[0]}` : v[0]),
- width
- )
+ table.forEach(function (v) {
+ width = Math.max(stringWidth(v[0]), width)
})
// if we've enabled 'wrap' we should limit
@@ -371,11 +334,11 @@ module.exports = function usage (yargs, y18n) {
// are copied to the keys being aliased.
function normalizeAliases () {
// handle old demanded API
- const demandedOptions = yargs.getDemandedOptions()
- const options = yargs.getOptions()
+ var demandedOptions = yargs.getDemandedOptions()
+ var options = yargs.getOptions()
- ;(Object.keys(options.alias) || []).forEach((key) => {
- options.alias[key].forEach((alias) => {
+ ;(Object.keys(options.alias) || []).forEach(function (key) {
+ options.alias[key].forEach(function (alias) {
// copy descriptions.
if (descriptions[alias]) self.describe(key, descriptions[alias])
// copy demanded.
@@ -394,41 +357,43 @@ module.exports = function usage (yargs, y18n) {
// given a set of keys, place any keys that are
// ungrouped under the 'Options:' grouping.
function addUngroupedKeys (keys, aliases, groups) {
- let groupedKeys = []
- let toCheck = null
- Object.keys(groups).forEach((group) => {
+ var groupedKeys = []
+ var toCheck = null
+ Object.keys(groups).forEach(function (group) {
groupedKeys = groupedKeys.concat(groups[group])
})
- keys.forEach((key) => {
+ keys.forEach(function (key) {
toCheck = [key].concat(aliases[key])
- if (!toCheck.some(k => groupedKeys.indexOf(k) !== -1)) {
+ if (!toCheck.some(function (k) {
+ return groupedKeys.indexOf(k) !== -1
+ })) {
groups[defaultGroup].push(key)
}
})
return groupedKeys
}
- self.showHelp = (level) => {
+ self.showHelp = function (level) {
const logger = yargs._getLoggerInstance()
if (!level) level = 'error'
- const emit = typeof level === 'function' ? level : logger[level]
+ var emit = typeof level === 'function' ? level : logger[level]
emit(self.help())
}
- self.functionDescription = (fn) => {
- const description = fn.name ? require('decamelize')(fn.name, '-') : __('generated-value')
+ self.functionDescription = function (fn) {
+ var description = fn.name ? require('decamelize')(fn.name, '-') : __('generated-value')
return ['(', description, ')'].join('')
}
- self.stringifiedValues = function stringifiedValues (values, separator) {
- let string = ''
- const sep = separator || ', '
- const array = [].concat(values)
+ self.stringifiedValues = function (values, separator) {
+ var string = ''
+ var sep = separator || ', '
+ var array = [].concat(values)
if (!values || !array.length) return string
- array.forEach((value) => {
+ array.forEach(function (value) {
if (string.length) string += sep
string += JSON.stringify(value)
})
@@ -439,7 +404,7 @@ module.exports = function usage (yargs, y18n) {
// format the default-value-string displayed in
// the right-hand column.
function defaultString (value, defaultDescription) {
- let string = `[${__('default:')} `
+ var string = '[' + __('default:') + ' '
if (value === undefined && !defaultDescription) return null
@@ -448,7 +413,7 @@ module.exports = function usage (yargs, y18n) {
} else {
switch (typeof value) {
case 'string':
- string += `"${value}"`
+ string += JSON.stringify(value)
break
case 'object':
string += JSON.stringify(value)
@@ -458,12 +423,12 @@ module.exports = function usage (yargs, y18n) {
}
}
- return `${string}]`
+ return string + ']'
}
// guess the width of the console window, max-width 80.
function windowWidth () {
- const maxWidth = 80
+ var maxWidth = 80
if (typeof process === 'object' && process.stdout && process.stdout.columns) {
return Math.min(maxWidth, process.stdout.columns)
} else {
@@ -472,47 +437,47 @@ module.exports = function usage (yargs, y18n) {
}
// logic for displaying application version.
- let version = null
- self.version = (ver) => {
+ var version = null
+ self.version = function (ver) {
version = ver
}
- self.showVersion = () => {
+ self.showVersion = function () {
const logger = yargs._getLoggerInstance()
- logger.log(version)
+ if (typeof version === 'function') logger.log(version())
+ else logger.log(version)
}
- self.reset = function reset (localLookup) {
+ self.reset = function (localLookup) {
// do not reset wrap here
// do not reset fails here
failMessage = null
failureOutput = false
- usages = []
- usageDisabled = false
+ usage = undefined
epilog = undefined
examples = []
commands = []
- descriptions = objFilter(descriptions, (k, v) => !localLookup[k])
+ descriptions = objFilter(descriptions, function (k, v) {
+ return !localLookup[k]
+ })
return self
}
- let frozen
- self.freeze = function freeze () {
+ var frozen
+ self.freeze = function () {
frozen = {}
frozen.failMessage = failMessage
frozen.failureOutput = failureOutput
- frozen.usages = usages
- frozen.usageDisabled = usageDisabled
+ frozen.usage = usage
frozen.epilog = epilog
frozen.examples = examples
frozen.commands = commands
frozen.descriptions = descriptions
}
- self.unfreeze = function unfreeze () {
+ self.unfreeze = function () {
failMessage = frozen.failMessage
failureOutput = frozen.failureOutput
- usages = frozen.usages
- usageDisabled = frozen.usageDisabled
+ usage = frozen.usage
epilog = frozen.epilog
examples = frozen.examples
commands = frozen.commands
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/validation.js b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/validation.js
index f4655b4fdc..2f9ff8e6cf 100644
--- a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/validation.js
+++ b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/validation.js
@@ -1,18 +1,16 @@
-'use strict'
-const argsert = require('./argsert')
const objFilter = require('./obj-filter')
const specialKeys = ['$0', '--', '_']
// validation-type-stuff, missing params,
// bad implications, custom checks.
-module.exports = function validation (yargs, usage, y18n) {
+module.exports = function (yargs, usage, y18n) {
const __ = y18n.__
const __n = y18n.__n
const self = {}
// validate appropriate # of non-option
// arguments were provided, i.e., '_'.
- self.nonOptionCount = function nonOptionCount (argv) {
+ self.nonOptionCount = function (argv) {
const demandedCommands = yargs.getDemandedCommands()
// don't count currently executing commands
const _s = argv._.length - yargs.getContext().commands.length
@@ -46,7 +44,7 @@ module.exports = function validation (yargs, usage, y18n) {
// validate the appropriate # of <required>
// positional arguments were provided:
- self.positionalCount = function positionalCount (required, observed) {
+ self.positionalCount = function (required, observed) {
if (observed < required) {
usage.fail(
__('Not enough non-option arguments: got %s, need at least %s', observed, required)
@@ -54,12 +52,44 @@ module.exports = function validation (yargs, usage, y18n) {
}
}
+ // make sure that any args that require an
+ // value (--foo=bar), have a value.
+ self.missingArgumentValue = function (argv) {
+ const defaultValues = [true, false, '']
+ const options = yargs.getOptions()
+
+ if (options.requiresArg.length > 0) {
+ const missingRequiredArgs = []
+
+ options.requiresArg.forEach(function (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) {
+ self.requiredArguments = function (argv) {
const demandedOptions = yargs.getDemandedOptions()
- let missing = null
+ var missing = null
- Object.keys(demandedOptions).forEach((key) => {
+ Object.keys(demandedOptions).forEach(function (key) {
if (!argv.hasOwnProperty(key) || typeof argv[key] === 'undefined') {
missing = missing || {}
missing[key] = demandedOptions[key]
@@ -68,14 +98,14 @@ module.exports = function validation (yargs, usage, y18n) {
if (missing) {
const customMsgs = []
- Object.keys(missing).forEach((key) => {
+ Object.keys(missing).forEach(function (key) {
const msg = missing[key]
if (msg && customMsgs.indexOf(msg) < 0) {
customMsgs.push(msg)
}
})
- const customMsg = customMsgs.length ? `\n${customMsgs.join('\n')}` : ''
+ const customMsg = customMsgs.length ? '\n' + customMsgs.join('\n') : ''
usage.fail(__n(
'Missing required argument: %s',
@@ -87,23 +117,33 @@ module.exports = function validation (yargs, usage, y18n) {
}
// check for unknown arguments (strict-mode).
- self.unknownArguments = function unknownArguments (argv, aliases, positionalMap) {
+ self.unknownArguments = function (argv, aliases, positionalMap) {
+ const aliasLookup = {}
+ const descriptions = usage.getDescriptions()
+ const demandedOptions = yargs.getDemandedOptions()
const commandKeys = yargs.getCommandInstance().getCommands()
const unknown = []
const currentContext = yargs.getContext()
- Object.keys(argv).forEach((key) => {
+ Object.keys(aliases).forEach(function (key) {
+ aliases[key].forEach(function (alias) {
+ aliasLookup[alias] = key
+ })
+ })
+
+ Object.keys(argv).forEach(function (key) {
if (specialKeys.indexOf(key) === -1 &&
+ !descriptions.hasOwnProperty(key) &&
+ !demandedOptions.hasOwnProperty(key) &&
!positionalMap.hasOwnProperty(key) &&
!yargs._getParseContext().hasOwnProperty(key) &&
- !aliases.hasOwnProperty(key)
- ) {
+ !aliasLookup.hasOwnProperty(key)) {
unknown.push(key)
}
})
if (commandKeys.length > 0) {
- argv._.slice(currentContext.commands.length).forEach((key) => {
+ argv._.slice(currentContext.commands.length).forEach(function (key) {
if (commandKeys.indexOf(key) === -1) {
unknown.push(key)
}
@@ -121,19 +161,18 @@ module.exports = function validation (yargs, usage, y18n) {
}
// validate arguments limited to enumerated choices
- self.limitedChoices = function limitedChoices (argv) {
+ self.limitedChoices = function (argv) {
const options = yargs.getOptions()
const invalid = {}
if (!Object.keys(options.choices).length) return
- Object.keys(argv).forEach((key) => {
+ Object.keys(argv).forEach(function (key) {
if (specialKeys.indexOf(key) === -1 &&
options.choices.hasOwnProperty(key)) {
- [].concat(argv[key]).forEach((value) => {
+ [].concat(argv[key]).forEach(function (value) {
// TODO case-insensitive configurability
- if (options.choices[key].indexOf(value) === -1 &&
- value !== undefined) {
+ if (options.choices[key].indexOf(value) === -1) {
invalid[key] = (invalid[key] || []).concat(value)
}
})
@@ -144,31 +183,31 @@ module.exports = function validation (yargs, usage, y18n) {
if (!invalidKeys.length) return
- let msg = __('Invalid values:')
- invalidKeys.forEach((key) => {
- msg += `\n ${__(
+ var msg = __('Invalid values:')
+ invalidKeys.forEach(function (key) {
+ msg += '\n ' + __(
'Argument: %s, Given: %s, Choices: %s',
key,
usage.stringifiedValues(invalid[key]),
usage.stringifiedValues(options.choices[key])
- )}`
+ )
})
usage.fail(msg)
}
// custom checks, added using the `check` option on yargs.
- let checks = []
- self.check = function check (f, global) {
+ var checks = []
+ self.check = function (f, global) {
checks.push({
func: f,
- global
+ global: global
})
}
- self.customChecks = function customChecks (argv, aliases) {
- for (let i = 0, f; (f = checks[i]) !== undefined; i++) {
- const func = f.func
- let result = null
+ self.customChecks = function (argv, aliases) {
+ for (var i = 0, f; (f = checks[i]) !== undefined; i++) {
+ var func = f.func
+ var result = null
try {
result = func(argv, aliases)
} catch (err) {
@@ -185,129 +224,107 @@ module.exports = function validation (yargs, usage, y18n) {
}
// check implications, argument foo implies => argument bar.
- let implied = {}
- self.implies = function implies (key, value) {
- argsert('<string|object> [array|number|string]', [key, value], arguments.length)
-
+ var implied = {}
+ self.implies = function (key, value) {
if (typeof key === 'object') {
- Object.keys(key).forEach((k) => {
+ Object.keys(key).forEach(function (k) {
self.implies(k, key[k])
})
} else {
yargs.global(key)
- if (!implied[key]) {
- implied[key] = []
- }
- if (Array.isArray(value)) {
- value.forEach((i) => self.implies(key, i))
- } else {
- implied[key].push(value)
- }
+ implied[key] = value
}
}
- self.getImplied = function getImplied () {
+ self.getImplied = function () {
return implied
}
- self.implications = function implications (argv) {
+ self.implications = function (argv) {
const implyFail = []
- Object.keys(implied).forEach((key) => {
+ Object.keys(implied).forEach(function (key) {
+ var num
const origKey = key
- ;(implied[key] || []).forEach((value) => {
- let num
- let key = origKey
- const origValue = value
-
- // convert string '1' to number 1
- num = Number(key)
- key = isNaN(num) ? key : num
-
- if (typeof key === 'number') {
- // check length of argv._
- key = argv._.length >= key
- } else if (key.match(/^--no-.+/)) {
- // check if key doesn't exist
- key = key.match(/^--no-(.+)/)[1]
- key = !argv[key]
- } else {
- // check if key exists
- key = argv[key]
- }
+ var value = implied[key]
+
+ // convert string '1' to number 1
+ num = Number(key)
+ key = isNaN(num) ? key : num
+
+ if (typeof key === 'number') {
+ // check length of argv._
+ key = argv._.length >= key
+ } else if (key.match(/^--no-.+/)) {
+ // check if key doesn't exist
+ key = key.match(/^--no-(.+)/)[1]
+ key = !argv[key]
+ } else {
+ // check if key exists
+ key = argv[key]
+ }
- num = Number(value)
- value = isNaN(num) ? value : num
+ num = Number(value)
+ value = isNaN(num) ? value : num
- if (typeof value === 'number') {
- value = argv._.length >= value
- } else if (value.match(/^--no-.+/)) {
- value = value.match(/^--no-(.+)/)[1]
- value = !argv[value]
- } else {
- value = argv[value]
- }
- if (key && !value) {
- implyFail.push(` ${origKey} -> ${origValue}`)
- }
- })
+ if (typeof value === 'number') {
+ value = argv._.length >= value
+ } else if (value.match(/^--no-.+/)) {
+ value = value.match(/^--no-(.+)/)[1]
+ value = !argv[value]
+ } else {
+ value = argv[value]
+ }
+
+ if (key && !value) {
+ implyFail.push(origKey)
+ }
})
if (implyFail.length) {
- let msg = `${__('Implications failed:')}\n`
+ var msg = __('Implications failed:') + '\n'
- implyFail.forEach((value) => {
- msg += (value)
+ implyFail.forEach(function (key) {
+ msg += (' ' + key + ' -> ' + implied[key])
})
usage.fail(msg)
}
}
- let conflicting = {}
- self.conflicts = function conflicts (key, value) {
- argsert('<string|object> [array|string]', [key, value], arguments.length)
-
+ var conflicting = {}
+ self.conflicts = function (key, value) {
if (typeof key === 'object') {
- Object.keys(key).forEach((k) => {
+ Object.keys(key).forEach(function (k) {
self.conflicts(k, key[k])
})
} else {
yargs.global(key)
- if (!conflicting[key]) {
- conflicting[key] = []
- }
- if (Array.isArray(value)) {
- value.forEach((i) => self.conflicts(key, i))
- } else {
- conflicting[key].push(value)
- }
+ conflicting[key] = value
}
}
- self.getConflicting = () => conflicting
-
- self.conflicting = function conflictingFn (argv) {
- Object.keys(argv).forEach((key) => {
- if (conflicting[key]) {
- conflicting[key].forEach((value) => {
- // we default keys to 'undefined' that have been configured, we should not
- // apply conflicting check unless they are a value other than 'undefined'.
- if (value && argv[key] !== undefined && argv[value] !== undefined) {
- usage.fail(__(`Arguments ${key} and ${value} are mutually exclusive`))
- }
- })
+ self.getConflicting = function () {
+ return conflicting
+ }
+
+ self.conflicting = function (argv) {
+ var args = Object.getOwnPropertyNames(argv)
+
+ args.forEach(function (arg) {
+ if (conflicting[arg] && args.indexOf(conflicting[arg]) !== -1) {
+ usage.fail(__('Arguments %s and %s are mutually exclusive', arg, conflicting[arg]))
}
})
}
- self.recommendCommands = function recommendCommands (cmd, potentialCommands) {
+ self.recommendCommands = function (cmd, potentialCommands) {
const distance = require('./levenshtein')
const threshold = 3 // if it takes more than three edits, let's move on.
- potentialCommands = potentialCommands.sort((a, b) => b.length - a.length)
+ potentialCommands = potentialCommands.sort(function (a, b) { return b.length - a.length })
- let recommended = null
- let bestDistance = Infinity
- for (let i = 0, candidate; (candidate = potentialCommands[i]) !== undefined; i++) {
- const d = distance(cmd, candidate)
+ var recommended = null
+ var bestDistance = Infinity
+ for (var i = 0, candidate; (candidate = potentialCommands[i]) !== undefined; i++) {
+ var d = distance(cmd, candidate)
if (d <= threshold && d < bestDistance) {
bestDistance = d
recommended = candidate
@@ -316,21 +333,27 @@ module.exports = function validation (yargs, usage, y18n) {
if (recommended) usage.fail(__('Did you mean %s?', recommended))
}
- self.reset = function reset (localLookup) {
- implied = objFilter(implied, (k, v) => !localLookup[k])
- conflicting = objFilter(conflicting, (k, v) => !localLookup[k])
- checks = checks.filter(c => c.global)
+ self.reset = function (localLookup) {
+ implied = objFilter(implied, function (k, v) {
+ return !localLookup[k]
+ })
+ conflicting = objFilter(conflicting, function (k, v) {
+ return !localLookup[k]
+ })
+ checks = checks.filter(function (c) {
+ return c.global
+ })
return self
}
- let frozen
- self.freeze = function freeze () {
+ var frozen
+ self.freeze = function () {
frozen = {}
frozen.implied = implied
frozen.checks = checks
frozen.conflicting = conflicting
}
- self.unfreeze = function unfreeze () {
+ self.unfreeze = function () {
implied = frozen.implied
checks = frozen.checks
conflicting = frozen.conflicting
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/yerror.js b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/yerror.js
index 53375a0f75..ad96a8776e 100644
--- a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/yerror.js
+++ b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/yerror.js
@@ -1,4 +1,3 @@
-'use strict'
function YError (msg) {
this.name = 'YError'
this.message = msg || 'yargs error'