UNPKG

@nu-art/commando

Version:
84 lines (83 loc) 4.04 kB
import { Constructor, LogLevel } from '@nu-art/ts-common'; import { LogTypes } from '../types'; import { BaseCommando } from '../core/BaseCommando'; export declare class CommandoInteractive extends BaseCommando { private shell; /** * Creates a new instance of CommandoInteractive merged with the provided plugins. * @param {Constructor<any>[]} plugins - The plugins to merge with CommandoInteractive. * @returns {CommandoInteractive} - The new instance of CommandoInteractive merged with the plugins. */ static create<T extends Constructor<any>[]>(...plugins: T): import("../core/class-merger").MergeTypes<[typeof BaseCommando, typeof CommandoInteractive, ...T]> & BaseCommando & CommandoInteractive; /** * Constructs a CommandoInteractive instance. */ constructor(); /** * Toggles or sets the debug mode. * @param {boolean} [debug] - If provided, sets the debug mode to this value. Otherwise, toggles the current debug mode. * @returns {boolean} - The current state of debug mode. */ debug(debug?: boolean): this; /** * Sets the UID for the shell. * @param {string} uid - The UID to set. * @returns {this} - The CommandoInteractive instance for method chaining. */ setUID(uid: string): this; /** * Closes the shell, optionally with a callback function. * @returns {this} - The CommandoInteractive instance for method chaining. */ close(): Promise<void>; /** * Kills the shell process with a given signal. * @param {NodeJS.Signals | number} [signal] - The signal to send to the process. * @returns {boolean} - Whether the kill signal was successfully sent. */ kill(signal?: NodeJS.Signals | number): boolean | undefined; /** * Gracefully kills a process by its PID. * @param {number} [pid] - The PID of the process to kill. */ gracefullyKill(pid?: number): Promise<void>; /** * Waits for a log entry that matches a specified pattern, then executes a callback. * @param {string | RegExp} filter - The pattern to match in log entries. * @param {(match: RegExpMatchArray) => any} callback - The callback to execute when a match is found. */ onLog(filter: string | RegExp, callback: (match: RegExpMatchArray) => any): this; /** * Executes commands asynchronously and listens for the PID. * * @param {Function} pidListener - A listener function to handle the PID. * @param {Function} [callback] - A callback function to handle the command output. * @returns {Promise<T>} - The result of the callback function. */ executeAsync<T>(pidListener: (pid: number) => void, callback?: (stdout: string, stderr: string, exitCode: number) => T): Promise<T>; /** * Executes commands and processes logs to extract exit code. * @param {Function} [callback] - A callback function to handle the command output. * @returns {Promise<T>} - The result of the callback function. */ execute<T>(callback?: (stdout: string, stderr: string, exitCode: number) => T): Promise<T>; /** * Adds a log processor to the shell. * @param {Function} processor - The log processor function to add. * @returns {this} - The CommandoInteractive instance for method chaining. */ addLogProcessor(processor: (log: string, std: LogTypes) => boolean): this; setLogLevelFilter(processor: (log: string, std: LogTypes) => LogLevel | undefined): this; /** * Removes a log processor from the shell. * @param {Function} processor - The log processor function to remove. * @returns {this} - The CommandoInteractive instance for method chaining. */ removeLogProcessor(processor: (log: string, std: LogTypes) => boolean): this; /** * Appends a command to the command list. * @param {string} command - The command to append. * @returns {this} - The CommandoInteractive instance for method chaining. */ append(command: string): this; }