@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
72 lines (71 loc) • 2.49 kB
TypeScript
/**
* ToolCommandParser - Parse and tokenize ToolCommand strings
*
* ARCHITECTURE DOCUMENTATION
* ==========================
*
* Handles parsing of command strings in the format:
* /commandName arg1 arg2 --flag value --boolFlag
*
* PARSING RULES:
* 1. Commands start with / (optional, stripped during parsing)
* 2. Positional arguments are space-separated
* 3. Flags start with -- or - (for short names)
* 4. Boolean flags have no value
* 5. String array flags use comma-separated values
* 6. Quoted strings preserve spaces
*
* AUTOCOMPLETE:
* The parser provides completion suggestions based on:
* - Cursor position in the input
* - Available commands in the registry
* - Argument autocomplete providers
* - Flag names and values
*/
import type { IToolCommand } from "./IToolCommand";
import { type ToolCommandScope } from "./IToolCommand";
import type { IToolCommandContext } from "./IToolCommandContext";
/**
* Result of parsing a command string.
*/
export interface ParsedToolCommand {
/** The command name (without leading /) */
commandName: string;
/** Positional arguments */
args: string[];
/** Flag values keyed by flag name (without --) */
flags: Record<string, string | boolean | string[]>;
/** The original input text */
originalText: string;
}
/**
* Parser for ToolCommand strings.
*/
export declare class ToolCommandParser {
/**
* Parse a command string into structured parts.
* @param text The command string to parse
* @returns Parsed command, or undefined if invalid
*/
static parse(text: string): ParsedToolCommand | undefined;
/**
* Tokenize a command string.
*/
private static tokenize;
/**
* Get autocomplete suggestions for a partial command.
* @param text The partial command text
* @param cursorPos Cursor position in the text
* @param registry The command registry to search
* @param context Execution context
*/
static getCompletions(text: string, cursorPos: number, registry: {
get: (name: string) => IToolCommand | undefined;
getCommandNames: (scope?: ToolCommandScope) => string[];
getAll: (scope?: ToolCommandScope) => IToolCommand[];
}, context: IToolCommandContext): Promise<string[]>;
/**
* Format a command with arguments for display/execution.
*/
static format(commandName: string, args: string[], flags: Record<string, string | boolean | string[]>): string;
}