cli-engine-command
Advanced tools
Comparing version 5.0.4 to 5.1.0
@@ -15,2 +15,8 @@ 'use strict'; | ||
var _output = require('./output'); | ||
var _output2 = _interopRequireDefault(_output); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function linewrap(length, s) { | ||
@@ -27,5 +33,5 @@ const linewrap = require('./output/linewrap'); | ||
let maxLength = max(items, '[0].length')[0].length + 1; | ||
let maxLength = max(items, '[0].length')[0].length; | ||
let lines = items.map(i => { | ||
let left = ` ${i[0]}`; | ||
let left = i[0]; | ||
let right = i[1]; | ||
@@ -35,3 +41,3 @@ if (!right) return left; | ||
right = linewrap(maxLength + 4, right); | ||
return `${left} # ${right}`; | ||
return `${left} ${right}`; | ||
}); | ||
@@ -54,29 +60,17 @@ return lines.join('\n'); | ||
function renderFlags(flags) { | ||
flags.sort((a, b) => { | ||
if (a[1].char && !b[1].char) return -1; | ||
if (b[1].char && !a[1].char) return 1; | ||
if (a[0] < b[0]) return -1; | ||
return b[0] < a[0] ? 1 : 0; | ||
}); | ||
return renderList(flags.map(([name, f]) => { | ||
let label = []; | ||
if (f.char) label.push(`-${f.char}`); | ||
if (name) label.push(` --${name}`); | ||
let usage = f.hasValue ? ` ${name.toUpperCase()}` : ''; | ||
let description = f.description || ''; | ||
if (f.required || f.optional === false) description = `(required) ${description}`; | ||
return [label.join(',').trim() + usage, description]; | ||
})); | ||
} | ||
class Help { | ||
class Help { | ||
constructor(config) { | ||
constructor(config, output) { | ||
this.config = config; | ||
this.out = output || new _output2.default({ config }); | ||
} | ||
command(cmd) { | ||
let usage = `Usage: ${this.config.bin} ${buildUsage(cmd)}\n`; | ||
let color = this.out.color; | ||
let flags = Object.keys(cmd.flags || {}).map(f => [f, cmd.flags[f]]).filter(f => !f[1].hidden); | ||
return [usage, cmd.description ? `\n${cmd.description.trim()}\n` : '', flags.length ? `\n${renderFlags(flags)}\n` : '', cmd.help ? `\n${cmd.help.trim()}\n` : ''].join(''); | ||
let args = (cmd.args || []).filter(a => !a.hidden); | ||
let hasFlags = flags.length ? ` ${color.blue('[flags]')}` : ''; | ||
let usage = ` | ||
${color.bold('Usage:')} ${this.config.bin} ${buildUsage(cmd)}${hasFlags}\n`; | ||
return [usage, cmd.description ? `\n${color.bold(cmd.description.trim())}\n` : '', this.renderArgs(args), this.renderFlags(flags), cmd.help ? `\n${cmd.help.trim()}\n` : ''].join(''); | ||
} | ||
@@ -87,3 +81,29 @@ | ||
} | ||
renderArgs(args) { | ||
if (!args.find(f => f.description)) return ''; | ||
return '\n' + renderList(args.map(a => { | ||
return [a.name.toUpperCase(), this.out.color.gray(a.description)]; | ||
})) + '\n'; | ||
} | ||
renderFlags(flags) { | ||
if (!flags.length) return ''; | ||
flags.sort((a, b) => { | ||
if (a[1].char && !b[1].char) return -1; | ||
if (b[1].char && !a[1].char) return 1; | ||
if (a[0] < b[0]) return -1; | ||
return b[0] < a[0] ? 1 : 0; | ||
}); | ||
return `\n${this.out.color.blue('Flags:')}\n` + renderList(flags.map(([name, f]) => { | ||
let label = []; | ||
if (f.char) label.push(`-${f.char}`); | ||
if (name) label.push(` --${name}`); | ||
let usage = f.hasValue ? ` ${name.toUpperCase()}` : ''; | ||
let description = f.description || ''; | ||
if (f.required || f.optional === false) description = `(required) ${description}`; | ||
return [` ${label.join(',').trim()}` + usage, this.out.color.gray(description)]; | ||
})) + '\n'; | ||
} | ||
} | ||
exports.default = Help; |
{ | ||
"name": "cli-engine-command", | ||
"description": "base CLI command for cli-engine", | ||
"version": "5.0.4", | ||
"version": "5.1.0", | ||
"author": "Jeff Dickey @dickeyxxx", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/heroku/cli-engine-command/issues", |
Sorry, the diff of this file is not supported yet
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
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
132580
1925