diff options
Diffstat (limited to 'node_modules/yargs/lib/usage.js')
-rw-r--r-- | node_modules/yargs/lib/usage.js | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/node_modules/yargs/lib/usage.js b/node_modules/yargs/lib/usage.js index 555ffb52b..43f71225c 100644 --- a/node_modules/yargs/lib/usage.js +++ b/node_modules/yargs/lib/usage.js @@ -3,6 +3,7 @@ const stringWidth = require('string-width') const objFilter = require('./obj-filter') const setBlocking = require('set-blocking') +const YError = require('./yerror') module.exports = function (yargs, y18n) { const __ = y18n.__ @@ -50,7 +51,7 @@ module.exports = function (yargs, y18n) { } } - err = err || new Error(msg) + err = err || new YError(msg) if (yargs.getExitProcess()) { return yargs.exit(1) } else if (yargs._hasParseCallback()) { @@ -76,8 +77,15 @@ module.exports = function (yargs, y18n) { } var commands = [] - self.command = function (cmd, description, aliases) { - commands.push([cmd, description || '', aliases]) + self.command = function (cmd, description, isDefault, aliases) { + // the last default wins, so cancel out any previously set default + if (isDefault) { + commands = commands.map(function (cmdArray) { + cmdArray[2] = false + return cmdArray + }) + } + commands.push([cmd, description || '', isDefault, aliases]) } self.getCommands = function () { return commands @@ -165,8 +173,13 @@ module.exports = function (yargs, y18n) { {text: command[0], padding: [0, 2, 0, 2], width: maxWidth(commands, theWrap) + 4}, {text: command[1]} ) - if (command[2] && command[2].length) { - ui.div({text: '[' + __('aliases:') + ' ' + command[2].join(', ') + ']', padding: [0, 0, 0, 2], align: 'right'}) + 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(', ') + ']') + } + if (hints.length) { + ui.div({text: hints.join(' '), padding: [0, 0, 0, 2], align: 'right'}) } else { ui.div() } @@ -234,7 +247,7 @@ module.exports = function (yargs, y18n) { var extra = [ type, - demandedOptions[key] ? '[' + __('required') + ']' : 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]) @@ -261,10 +274,24 @@ module.exports = function (yargs, y18n) { }) examples.forEach(function (example) { - ui.div( - {text: example[0], padding: [0, 2, 0, 2], width: maxWidth(examples, theWrap) + 4}, - example[1] - ) + if (example[1] === '') { + ui.div( + { + text: example[0], + padding: [0, 2, 0, 2] + } + ) + } else { + ui.div( + { + text: example[0], + padding: [0, 2, 0, 2], + width: maxWidth(examples, theWrap) + 4 + }, { + text: example[1] + } + ) + } }) ui.div() @@ -315,7 +342,7 @@ module.exports = function (yargs, y18n) { // copy descriptions. if (descriptions[alias]) self.describe(key, descriptions[alias]) // copy demanded. - if (demandedOptions[alias]) yargs.demandOption(key, demandedOptions[alias].msg) + if (alias in demandedOptions) yargs.demandOption(key, demandedOptions[alias]) // type messages. if (~options.boolean.indexOf(alias)) yargs.boolean(key) if (~options.count.indexOf(alias)) yargs.count(key) @@ -421,7 +448,7 @@ module.exports = function (yargs, y18n) { else logger.log(version) } - self.reset = function (globalLookup) { + self.reset = function (localLookup) { // do not reset wrap here // do not reset fails here failMessage = null @@ -431,7 +458,7 @@ module.exports = function (yargs, y18n) { examples = [] commands = [] descriptions = objFilter(descriptions, function (k, v) { - return globalLookup[k] + return !localLookup[k] }) return self } |