Skip to content

Commit c16e4a9

Browse files
committed
feat: add runInteractive method for interactive command execution
1 parent 9892b8b commit c16e4a9

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/lib/shell.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,30 @@ export class Shell {
4040
}
4141
}
4242

43+
// Runs a command interactively, so the user can interact with stdin/stdout/stderr directly.
44+
async runInteractive(
45+
command: string,
46+
errorOnCodeNonZero: boolean = true
47+
): Promise<{ code: number | null; signal: string | null }> {
48+
return await new Promise((resolve, reject) => {
49+
const cp = spawn('bash', ['-c', command], {
50+
cwd: this.cwd,
51+
stdio: 'inherit', // give full TTY passthrough
52+
});
53+
54+
cp.on('error', reject);
55+
56+
cp.on('close', (code, signal) => {
57+
const result = { code, signal };
58+
if (errorOnCodeNonZero && code !== 0) {
59+
reject(result);
60+
} else {
61+
resolve(result);
62+
}
63+
});
64+
});
65+
}
66+
4367
async stderr(command: string, errorOnCodeZero?: boolean): Promise<string> {
4468
const result = await this.run(command, errorOnCodeZero);
4569
return result.stderr.trim();

0 commit comments

Comments
 (0)