@nu-art/commando
Version:
Shell command execution framework with interactive sessions, CLI parameter resolution, and plugin system for building and executing shell scripts programmatically
86 lines (85 loc) • 3.45 kB
TypeScript
import { Constructor } from '@nu-art/ts-common';
import { CommandBuilder } from './CommandBuilder.js';
/**
* Base class for shell command execution with plugin support.
*
* Provides a fluent API for building shell commands with indentation support.
* Uses a plugin system that merges multiple classes into a single instance
* using the class-merger utility.
*
* **Plugin System**: The `_create()` method uses class merging to combine
* BaseCommando with plugin classes, creating a single instance with methods
* from all merged classes.
*
* **Command Building**: Commands are built using the CommandBuilder, which
* supports indentation and newline handling. The builder accumulates commands
* until `execute()` is called.
*
* **Note**: The `builder` field is marked readonly but is actually set via
* `@ts-ignore` in `_create()`. This is a type safety issue.
*/
export declare class BaseCommando {
/** Command builder for accumulating shell commands */
protected readonly builder: CommandBuilder;
/** Debug mode flag (enables verbose logging) */
protected _debug: boolean;
/**
* Creates a new BaseCommando instance merged with provided plugins.
*
* Uses class merging to combine BaseCommando with plugin classes into
* a single instance. The builder is initialized after merging.
*
* **Note**: Uses `@ts-ignore` to set the readonly `builder` field.
*
* @template T - Array of constructor types to merge
* @param plugins - Plugin classes to merge with BaseCommando
* @returns Merged instance with BaseCommando and all plugin methods
*/
static _create<T extends Constructor<any>[]>(...plugins: T): import("./class-merger.js").MergeTypes<[typeof BaseCommando, ...T]> & BaseCommando;
/**
* Constructs a BaseCommando instance.
*/
constructor();
/**
* Toggles or sets debug mode.
*
* When debug is enabled, shell execution provides verbose logging.
*
* @param debug - Optional value to set (if omitted, toggles current state)
* @returns This instance for method chaining
*/
debug(debug?: boolean): this;
/**
* Appends a command to the command list.
* @param {string} command - The command to append.
* @returns {this} - The BaseCommando instance for method chaining.
*/
append(command: string): this;
mark(): this;
/**
* Increases the current indentation level by one.
* @returns {this} - The BaseCommando instance for method chaining.
*/
indentIn(): this;
/**
* Decreases the current indentation level by one.
* @returns {this} - The BaseCommando instance for method chaining.
*/
indentOut(): this;
/**
* Appends an empty line to the script for readability.
* @returns {this} - The BaseCommando instance for method chaining.
*/
emptyLine(): this;
/**
* Executes the commands. Must be overridden in a subclass.
* @throws {ImplementationMissingException} - Always throws this exception.
*/
execute(): Promise<void>;
/**
* Executes the commands with a callback. Must be overridden in a subclass.
* @param {Function} callback - A callback function to handle the command output.
* @throws {ImplementationMissingException} - Always throws this exception.
*/
execute<T>(callback: (stdout: string, stderr: string, exitCode: number) => T): Promise<T>;
}