mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Add virtual shell command
This commit is contained in:
9 files changed
+807
-4
No files matched your search
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Interface for shell command implementations
|
||||
*/
|
||||
export interface ShellCommand {
|
||||
/** The name of the command (e.g., 'cat', 'ls', 'cd') */
|
||||
name: string;
|
||||
|
||||
/** Brief description of what the command does */
|
||||
description: string;
|
||||
|
||||
/** Usage syntax for the command */
|
||||
usage: string;
|
||||
|
||||
/**
|
||||
* Execute the command with the given arguments
|
||||
* @param args Array of command arguments (excluding the command name itself)
|
||||
* @param cwd Current working directory
|
||||
* @returns Promise resolving to the command output or error message
|
||||
*/
|
||||
execute(args: string[], cwd: string): Promise<ShellCommandResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of executing a shell command
|
||||
*/
|
||||
export interface ShellCommandResult {
|
||||
/** Exit code (0 for success, non-zero for error) */
|
||||
exitCode: number;
|
||||
|
||||
/** Standard output content */
|
||||
stdout: string;
|
||||
|
||||
/** Standard error content */
|
||||
stderr: string;
|
||||
|
||||
/** New working directory (for commands like 'cd' that change directory) */
|
||||
newCwd?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a successful command result
|
||||
*/
|
||||
export function createSuccessResult(stdout: string, newCwd?: string): ShellCommandResult {
|
||||
return {
|
||||
exitCode: 0,
|
||||
stdout,
|
||||
stderr: '',
|
||||
newCwd,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an error command result
|
||||
*/
|
||||
export function createErrorResult(stderr: string, exitCode: number = 1): ShellCommandResult {
|
||||
return {
|
||||
exitCode,
|
||||
stdout: '',
|
||||
stderr,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user