@qbyco/tjs-cli
Version:
TrafaletJS CLI Tool
73 lines (62 loc) • 1.57 kB
JavaScript
const CLICommand = require("../../lib/cli/Command/CLICommand");
/**
* @module tasks/commands/Help
*/
class Help extends CLICommand {
/**
* @constructor
* @param lib
* @memberof Help
*/
constructor (lib) {
super("help");
this.lib = lib;
this.indent = " ";
}
/**
* Display all methods within the CLI tool
* @method mainAction
* @memberof Help
*/
mainAction () {
const npmConfig = require('../../package');
console.log(this.lib.chalk.white('\nTrafaletJS CLI ----------------'));
console.log(this.lib.chalk.green('Ver:', npmConfig.version) + "\n");
this.displayHelpFor(this);
this.lib.cli.getRepository().getCommands().forEach((command) => {
if ("help" !== command.getName()) {
this.displayHelpFor(command);
}
});
}
/**
* @method displayHelpFor
* @param {CLICommand} command
*/
displayHelpFor (command) {
console.log(this.lib.chalk.red(command.getName()));
const help = command.help();
help.forEach((value, key) => {
if(key) {
console.log(this.indent + this.lib.chalk.cyan([command.getName(), key].join(":")) + " " + this.lib.chalk.white(value));
} else {
console.log(this.indent + this.lib.chalk.cyan(value));
}
});
}
/**
* @method help
* @returns {Map}
*/
help () {
let help = new Map();
help.set(null, "Show this help");
return help;
}
}
module.exports = {
init: function (lib) {
lib.cli.getRepository().addCommand(new Help(lib));
},
run: function (lib) {}
};