UNPKG

mira-consciousness

Version:

Memory & Intelligence Retention Archive - Preserving The Spark

63 lines 1.94 kB
import { CommandBuilder, createActionHandler } from './command-builder.js'; /** * Registry for managing command registration */ export class CommandRegistry { program; commandActions; constructor(program, commandActions) { this.program = program; this.commandActions = commandActions; } /** * Register all commands from configuration */ async registerAll(configs) { for (const config of configs) { await this.registerCommand(config); } } /** * Register a single command */ async registerCommand(config) { // Handle commands that return Command objects if (config.createCommand) { const commandFunction = this.commandActions[config.createCommand]; if (commandFunction) { const command = commandFunction(); this.program.addCommand(command); } return; } // Use CommandBuilder for cleaner command creation const builder = CommandBuilder.fromConfig(config); // Add action if specified if (config.action) { const handler = createActionHandler(config.action, config.isLazy ? config.importPath : undefined, config.isLazy ? undefined : this.commandActions); builder.action(handler); } // Add the built command to program const command = builder.build(); this.program.addCommand(command); } /** * Get the program instance */ getProgram() { return this.program; } } /** * Create a map of all command actions from imports */ export function createCommandActionMap(imports) { const actionMap = {}; Object.entries(imports).forEach(([key, value]) => { if (typeof value === 'function') { actionMap[key] = value; } }); return actionMap; } //# sourceMappingURL=command-registry.js.map