Files
hose-use/src/cli.ts
T

46 lines
1.3 KiB
TypeScript
Executable File

#!/usr/bin/env bun
import { fileURLToPath } from "node:url";
import { dirname } from "node:path";
import { runCli } from "./cli/runner.js";
process.stdout.on("error", (err: any) => {
if (err?.code === "EPIPE") process.exit(0);
});
process.stderr.on("error", (err: any) => {
if (err?.code === "EPIPE") process.exit(0);
});
const entryFile = fileURLToPath(import.meta.url);
const appRoot = dirname(dirname(entryFile));
// Unix Multicall Binary Pattern: 检测是否通过 hose-aipro 符号链接/别名唤起
const candidates = [process.argv0, process.argv[1], process.argv[0]].filter(Boolean) as string[];
const isAiPro = candidates.some((c) => {
const base = c.split("/").pop() || "";
return base.includes("hose-aipro") || base === "aipro" || base.includes("aipro-cli");
});
const result = isAiPro
? await (await import("./aipro-cli.js")).runAiProCli(process.argv.slice(2))
: await runCli(process.argv.slice(2), {
appRoot,
entryFile,
});
try {
if (result.stdout) process.stdout.write(result.stdout);
} catch (err: any) {
if (err?.code !== "EPIPE") throw err;
}
try {
if (result.stderr) {
process.stderr.write(`${result.stderr}${result.stderr.endsWith("\n") ? "" : "\n"}`);
}
} catch (err: any) {
if (err?.code !== "EPIPE") throw err;
}
process.exitCode = result.exitCode;