@pobuca/xsc
Version:
A cli tool with common git command sets.
48 lines • 2.02 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const eventemitter2_1 = require("eventemitter2");
const xcommit_1 = require("./commands/xcommit");
const xfeature_1 = require("./commands/xfeature");
const xhotfix_1 = require("./commands/xhotfix");
const xrelease_1 = require("./commands/xrelease");
const xsc_1 = require("./commands/xsc");
class CLI extends eventemitter2_1.EventEmitter2 {
constructor(terminal) {
super();
this.terminal = terminal;
}
invoke(commandName, parameters) {
return __awaiter(this, void 0, void 0, function* () {
const CommandConstructor = this.lookup(commandName);
const commandInstance = new CommandConstructor(this.terminal);
commandInstance.onAny(this.emit.bind(this));
yield commandInstance.invoke(...parameters);
});
}
lookup(commandName) {
for (const CommandConstructor of CLI.commands) {
if (CommandConstructor.command === commandName) {
return CommandConstructor;
}
}
throw new Error(`Unknown command: ${commandName}`);
}
}
exports.default = CLI;
CLI.commands = [
xcommit_1.default,
xfeature_1.default,
xrelease_1.default,
xhotfix_1.default,
xsc_1.default
];
//# sourceMappingURL=CLI.js.map