bit-bin
Version:
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b
52 lines (38 loc) • 802 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getID = getID;
exports.default = void 0;
function _exceptions() {
const data = require("./exceptions");
_exceptions = function () {
return data;
};
return data;
}
class CommandRegistry {
constructor(commands) {
this.commands = commands;
}
/**
* register a new command
*/
register(command) {
const id = CommandRegistry.getID(command);
if (this.commands[id]) {
throw new (_exceptions().AlreadyExistsError)('Command', id);
}
this.commands[id] = command;
}
/**
* return a command unique ID.
*/
static getID(cmd) {
return getID(cmd.name);
}
}
exports.default = CommandRegistry;
function getID(cmd) {
return cmd.split(' ')[0].trim();
}
;