Format commands plugins help output with indents

This commit is contained in:
Sunny 2017-06-21 00:32:02 +05:30
parent 569bb6901c
commit 084e6669bc

View File

@ -72,18 +72,19 @@ class CLI {
return false;
}
displayCommandUsage(commandObject, command) {
displayCommandUsage(commandObject, command, indents = 0) {
const dotsLength = 30;
// check if command has lifecycleEvents (can be executed)
if (commandObject.lifecycleEvents) {
const usage = commandObject.usage;
const dots = _.repeat('.', dotsLength - command.length);
this.consoleLog(`${chalk.yellow(command)} ${chalk.dim(dots)} ${usage}`);
const indent = _.repeat(' ', indents);
this.consoleLog(`${indent}${chalk.yellow(command)} ${chalk.dim(dots)} ${usage}`);
}
_.forEach(commandObject.commands, (subcommandObject, subcommand) => {
this.displayCommandUsage(subcommandObject, `${command} ${subcommand}`);
this.displayCommandUsage(subcommandObject, `${command} ${subcommand}`, indents);
});
}
@ -153,6 +154,14 @@ class CLI {
this.consoleLog('');
this.consoleLog(chalk.yellow.underline('Commands by plugin'));
this.consoleLog('');
_.forEach(this.loadedCommands, (details, command) => {
this.consoleLog(details.pluginName);
this.displayCommandUsage(details, command, 1);
this.consoleLog('');
});
}
generateCommandsHelp(commandsArray) {