UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

90 lines (89 loc) 3.04 kB
/** * ToolCommandRegistry - Central registry for all ToolCommands * * ARCHITECTURE DOCUMENTATION * ========================== * * This registry is the central hub for ToolCommand management: * * RESPONSIBILITIES: * 1. Hold all registered IToolCommand instances * 2. Provide lookup by command name or alias * 3. Execute commands with parsed arguments * 4. Provide autocomplete suggestions * 5. Filter commands by scope * 6. Generate help documentation * * SINGLETON PATTERN: * Use ToolCommandRegistry.instance to access the global registry. * Commands are registered at module load time. * * RELATED FILES: * - IToolCommand.ts: Command interface * - IToolCommandContext.ts: Execution context * - ToolCommandParser.ts: Command line parsing * - commands/: Individual command implementations */ import type { IToolCommand, IToolCommandResult } from "./IToolCommand"; import { ToolCommandScope } from "./IToolCommand"; import type { IToolCommandContext } from "./IToolCommandContext"; /** * Central registry for ToolCommands. */ export declare class ToolCommandRegistry { private static _instance; private commands; /** * Get the singleton instance. */ static get instance(): ToolCommandRegistry; /** * Register a ToolCommand. * @param command The command to register */ register(command: IToolCommand): void; /** * Register multiple commands. */ registerAll(commands: IToolCommand[]): void; /** * Get a command by name or alias. * @param name Command name or alias (case-insensitive) */ get(name: string): IToolCommand | undefined; /** * Check if a command exists. */ has(name: string): boolean; /** * Get all unique commands (excluding alias duplicates). * Optionally filter by scope. */ getAll(scope?: ToolCommandScope): IToolCommand[]; /** * Get all command names (for autocomplete). */ getCommandNames(scope?: ToolCommandScope): string[]; /** * Execute a command from a command string. * @param commandText Full command text (e.g., "/create template myproject --traits mob") * @param context Execution context * @returns Command result, or undefined if command not found */ execute(commandText: string, context: IToolCommandContext): Promise<IToolCommandResult | undefined>; /** * Execute a command with pre-parsed arguments. */ executeCommand(name: string, args: string[], flags: Record<string, string | boolean | string[]>, context: IToolCommandContext): Promise<IToolCommandResult | undefined>; /** * Get autocomplete suggestions for a partial command. * @param text The partial command text being typed * @param cursorPos The cursor position in the text * @param context Execution context */ getCompletions(text: string, cursorPos: number, context: IToolCommandContext): Promise<string[]>; /** * Clear all registered commands (for testing). */ clear(): void; }