@nu-art/commando
Version:
Shell command execution framework with interactive sessions, CLI parameter resolution, and plugin system for building and executing shell scripts programmatically
49 lines (48 loc) • 1.64 kB
TypeScript
import { ExecOptions } from 'child_process';
import { Logger } from '@nu-art/ts-common';
/**
* Extended ExecOptions with encoding support.
*/
export type CliOptions = ExecOptions & {
encoding: BufferEncoding | string | null;
};
/**
* Simple shell command executor using Node.js child_process.
*
* Executes shell commands synchronously via `exec()` and handles
* output conversion. Supports debug logging and custom shell/options.
*
* **Behavior**:
* - Uses `/bin/bash` as default shell
* - Converts Buffer output to UTF-8 strings
* - Logs stdout as info, stderr as error
* - Throws CliError on command failure
* - Supports UID tagging for log identification
*/
export declare class SimpleShell extends Logger {
/** Debug mode flag (enables verbose command logging) */
private _debug;
/** Execution options for child_process.exec() */
private cliOptions;
/**
* Executes a shell command and returns stdout/stderr.
*
* **Behavior**:
* - Logs command in debug mode (wrapped in triple quotes)
* - Converts Buffer output to UTF-8 strings
* - Logs stdout as info, stderr as error
* - Throws CliError if command fails (non-zero exit code)
*
* @param command - Shell command string to execute
* @returns Promise resolving to stdout and stderr strings
* @throws CliError if command execution fails
*/
execute: (command: string) => Promise<{
stdout: string;
stderr: string;
}>;
debug(debug?: boolean): this;
setShell(shell: string): void;
setOptions(options: Partial<CliOptions>): void;
setUID(uid: string): this;
}