import { CommandDiscoveryService, CommandRegistry } from '../lib/command-discovery'; /** * Utility class for working with the command registry */ export class CommandRegistryUtil { private static instance: CommandRegistryUtil; private registry: CommandRegistry | null = null; private discoveryService: CommandDiscoveryService; private constructor() { this.discoveryService = new CommandDiscoveryService(); } public static getInstance(): CommandRegistryUtil { if (!CommandRegistryUtil.instance) { CommandRegistryUtil.instance = new CommandRegistryUtil(); } return CommandRegistryUtil.instance; } /** * Get the command registry (cached after first call) */ public getRegistry(): CommandRegistry { if (!this.registry) { this.registry = this.discoveryService.discoverCommands(); } return this.registry; } /** * Get all read-only commands for testing */ public getReadOnlyCommands() { return this.getRegistry().readOnlyCommands; } /** * Get all state-changing commands */ public getStateChangingCommands() { return this.getRegistry().stateChangingCommands; } /** * Get commands for a specific namespace */ public getCommandsForNamespace(namespace: string) { return this.discoveryService.getCommandsForNamespace(namespace); } /** * Get a specific command */ public getCommand(namespace: string, commandName: string) { return this.discoveryService.getCommand(namespace, commandName); } /** * Generate command signature for CLI execution */ public generateCommandSignature(namespace: string, commandName: string): string | null { const command = this.getCommand(namespace, commandName); if (!command) { return null; } return this.discoveryService.generateCommandSignature(command); } /** * Get all available namespaces */ public getNamespaces(): string[] { return this.getRegistry().namespaces; } /** * Print registry statistics */ public printStats(): void { const registry = this.getRegistry(); console.log('Command Registry Statistics:'); console.log(` Total commands: ${registry.commands.length}`); console.log(` Namespaces: ${registry.namespaces.length} (${registry.namespaces.join(', ')})`); console.log(` Read-only commands: ${registry.readOnlyCommands.length}`); console.log(` State-changing commands: ${registry.stateChangingCommands.length}`); } /** * Refresh the registry (re-discover commands) */ public refresh(): void { this.registry = null; } } // Export a singleton instance for convenience export const commandRegistry = CommandRegistryUtil.getInstance();