UNPKG

@acot/cli

Version:
41 lines (40 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandContainer = void 0; class CommandContainer { constructor(commands) { const map = new Map(); commands.forEach((module) => { map.set(module.name, module); if (module.commands != null) { module.commands.forEach((child) => { map.set(`${module.name}.${child.name}`, child); }); } }); this._commands = map; } all() { return Array.from(this._commands.values()); } main() { const commands = []; this._commands.forEach((module, key) => { if (!key.includes('.')) { commands.push(module); } }); return commands; } get(name) { return this._commands.get(name); } mustGet(name) { const module = this.get(name); if (module == null) { throw new ReferenceError(`"${name}" command does not exists`); } return module; } } exports.CommandContainer = CommandContainer;