@qbyco/tjs-cli
Version:
TrafaletJS CLI Tool
48 lines (40 loc) • 931 B
JavaScript
/**
* @module lib/cli/Command/Executor
*/
class Executor {
/**
* @constructor
* @param {lib/cli/CLI} cli
*/
constructor (cli) {
this.cli = cli;
}
/**
* @method execute
* @throws Error
* @returns {boolean}
*/
execute () {
let found = false;
this.cli.getRepository().getCommands().forEach((command) => {
let method, suffix;
if (command.getName() === this.cli.getCommand().getName()) {
found = true;
suffix = "Action";
method = this.cli.getCommand().getAction() + suffix;
if ("function" === typeof command[method]) {
command[method]
.apply(
command,
this.cli.getCommand().getParams().concat([this.cli.getCommand().getFlags()])
);
}
}
});
if (! found) {
throw new Error("Command not found");
}
return true;
}
}
module.exports = Executor;