UNPKG

@qbyco/tjs-cli

Version:

TrafaletJS CLI Tool

73 lines (60 loc) 1.22 kB
/** * @module tasks/CLI */ class CLI { /** * @constructor * @param lib */ constructor (lib) { this.lib = lib; this.nodeExecutor = process.argv.shift(); this.scriptExecutor = process.argv.shift(); process.on("uncaughtException", (error) => { console.error(this.lib.chalk.red(error.message)); }); } /** * @method run * @returns {boolean} */ run() { this.lib.cli.take(process.argv); this.lib.events.emit( "beforeRun", this.getCommandEvent(), this.lib.cli.getCommand().getParams().concat([this.lib.cli.getCommand().getFlags()]) ); this.lib.cli.getExecutor().execute(); return true; } /** * @method getCommandEvent * @memberof CLI * @returns {string} */ getCommandEvent() { let parts; parts = [this.lib.cli.getCommand().getName()]; if (this.lib.cli.getCommand().getAction()) { parts.push(this.lib.cli.getCommand().getAction()); } return parts.join(":") } } module.exports = { /** * @method init * @param lib */ init: function (lib) { this.cli = new CLI(lib); }, /** * @method run * @param lib */ run: function (lib) { this.cli.run(); } };