Fix desktop CLI passthrough tty handling (#791)
* Fix desktop CLI passthrough tty handling * Fix desktop daemon manager test drift * Update daemon stop test after main merge * test(cli): isolate npx cache per CLI test
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { createCli } from "./cli.js";
|
||||
import { classifyInvocation } from "./classify.js";
|
||||
import { openDesktopWithProject } from "./commands/open.js";
|
||||
|
||||
export interface RunCliOptions {
|
||||
cwd?: string;
|
||||
nodeArgv?: [string, string];
|
||||
}
|
||||
|
||||
export function createCliParseArgv(input: {
|
||||
argv: string[];
|
||||
cwd: string;
|
||||
nodeArgv?: [string, string];
|
||||
}): string[] | { kind: "open-project"; resolvedPath: string } {
|
||||
const program = createCli();
|
||||
const knownCommands = new Set(program.commands.map((command) => command.name()));
|
||||
const invocation = classifyInvocation({
|
||||
argv: input.argv,
|
||||
knownCommands,
|
||||
cwd: input.cwd,
|
||||
});
|
||||
|
||||
if (invocation.kind === "open-project") {
|
||||
return invocation;
|
||||
}
|
||||
|
||||
const nodeArgv = input.nodeArgv ?? ["paseo", "paseo"];
|
||||
const cliArgv = invocation.argv.length === 0 ? ["onboard"] : invocation.argv;
|
||||
return [...nodeArgv, ...cliArgv];
|
||||
}
|
||||
|
||||
export async function runCli(argv: string[], options: RunCliOptions = {}): Promise<number> {
|
||||
const parseArgv = createCliParseArgv({
|
||||
argv,
|
||||
cwd: options.cwd ?? process.cwd(),
|
||||
nodeArgv: options.nodeArgv,
|
||||
});
|
||||
|
||||
if (!Array.isArray(parseArgv)) {
|
||||
await openDesktopWithProject(parseArgv.resolvedPath);
|
||||
return typeof process.exitCode === "number" ? process.exitCode : 0;
|
||||
}
|
||||
|
||||
const program = createCli();
|
||||
await program.parseAsync(parseArgv, { from: "node" });
|
||||
return typeof process.exitCode === "number" ? process.exitCode : 0;
|
||||
}
|
||||
Reference in New Issue
Block a user