mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
This change was applied to all directories under src/ except for the ui/ directory. Only .js files were searched. This was an automatic replacement from var to let for any variable declaration that doubles as the initial assignment. Ultimately we want most of these to be converted to const, but this commit is so large that it warrants breaking each step of automation up into its own commit. For example: `var foo = 'bar';` becomes `let foo = 'var';` This was accomplished by replacing: find: `var ([a-zA-Z_$][0-9a-zA-Z_$]*)(\s+)=` replace: `let $1$2=`
74 lines
1.6 KiB
JavaScript
74 lines
1.6 KiB
JavaScript
import _ from 'lodash';
|
|
|
|
module.exports = function (command, spaces) {
|
|
if (!_.size(command.commands)) {
|
|
return command.outputHelp();
|
|
}
|
|
|
|
let defCmd = _.find(command.commands, function (cmd) {
|
|
return cmd._name === 'serve';
|
|
});
|
|
|
|
let desc = !command.description() ? '' : command.description();
|
|
let cmdDef = !defCmd ? '' : `=${defCmd._name}`;
|
|
|
|
return (
|
|
`
|
|
Usage: ${command._name} [command${cmdDef}] [options]
|
|
|
|
${desc}
|
|
|
|
Commands:
|
|
${indent(commandsSummary(command), 2)}
|
|
|
|
${cmdHelp(defCmd)}
|
|
`
|
|
).trim().replace(/^/gm, spaces || '');
|
|
};
|
|
|
|
function indent(str, n) {
|
|
return String(str || '').trim().replace(/^/gm, _.repeat(' ', n));
|
|
}
|
|
|
|
function commandsSummary(program) {
|
|
let cmds = _.compact(program.commands.map(function (cmd) {
|
|
let name = cmd._name;
|
|
if (name === '*') return;
|
|
let opts = cmd.options.length ? ' [options]' : '';
|
|
let args = cmd._args.map(function (arg) {
|
|
return humanReadableArgName(arg);
|
|
}).join(' ');
|
|
|
|
return [
|
|
`${name} ${opts} ${args}`,
|
|
cmd.description()
|
|
];
|
|
}));
|
|
|
|
let cmdLColWidth = cmds.reduce(function (width, cmd) {
|
|
return Math.max(width, cmd[0].length);
|
|
}, 0);
|
|
|
|
return cmds.reduce(function (help, cmd) {
|
|
return `${help || ''}${_.padRight(cmd[0], cmdLColWidth)} ${cmd[1] || ''}\n`;
|
|
}, '');
|
|
}
|
|
|
|
function cmdHelp(cmd) {
|
|
if (!cmd) return '';
|
|
return (
|
|
|
|
`
|
|
"${cmd._name}" Options:
|
|
|
|
${indent(cmd.optionHelp(), 2)}
|
|
`
|
|
|
|
).trim();
|
|
|
|
}
|
|
|
|
function humanReadableArgName(arg) {
|
|
let nameOutput = arg.name + (arg.variadic === true ? '...' : '');
|
|
return arg.required ? '<' + nameOutput + '>' : '[' + nameOutput + ']';
|
|
}
|