mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
* 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
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
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;
|
|
}
|