UNPKG

@nu-art/commando

Version:

Shell command execution framework with interactive sessions, CLI parameter resolution, and plugin system for building and executing shell scripts programmatically

78 lines (77 loc) 2.73 kB
/** * Type definition for options used in the CommandBuilder class. */ type Options = { newlineDelimiter: string; indentation: number; }; /** * Builds shell commands with indentation and formatting support. * * Accumulates commands in an array and formats them with proper indentation. * Supports custom newline delimiters and indentation levels. Commands can * be split across multiple lines using the newline delimiter. * * **Behavior**: * - Commands are trimmed before adding * - Empty commands are preserved (for spacing) * - Indentation is applied per line when commands contain newlines * - `reset()` returns the accumulated command and clears the builder */ export declare class CommandBuilder { private initialCommands; /** Array of accumulated command strings */ commands: string[]; /** Current indentation level (number of indent steps) */ private indentation; /** Configuration options for formatting */ private option; /** * Constructs a CommandBuilder instance with given options. * @param {Partial<Options>} [options=defaultOptions] - Configuration options for the CommandBuilder instance. */ constructor(options?: Partial<Options>); /** * Generates a string of spaces for indentation based on the current indentation level. * @returns {string} - A string containing spaces for the current indentation level. */ protected getIndentation: () => string; setMark(): void; /** * Increases the current indentation level by one. */ readonly indentIn: () => void; /** * Decreases the current indentation level by one. */ readonly indentOut: () => void; /** * Appends an empty line to the command list for readability. * @returns {this} - The CommandBuilder instance for method chaining. */ emptyLine(): this; /** * Appends a command to the command list with proper indentation. * * **Behavior**: * - Splits the command by the newline delimiter (allows multi-line commands) * - Trims each line * - Applies current indentation to non-empty lines * - Preserves empty lines as-is (for spacing) * * @param command - Command string to append (can contain newlines) * @returns This instance for method chaining */ readonly append: (command: string) => this; /** * Retrieves the full command list as a single string. * @returns {string} - The full command list. */ getCommand(): string; /** * Resets the command list and returns the previously accumulated commands. * @returns {string} - The previously accumulated commands. */ reset(): string; } export {};