refactor(cli): split tjwater cli modules
Agent CI/CD / deploy-fallback-log (push) Has been cancelled
Agent CI/CD / docker-image (push) Has been cancelled

This commit is contained in:
2026-06-07 19:43:44 +08:00
parent ff87817fb5
commit 93d70da8be
23 changed files with 1720 additions and 740 deletions
+45
View File
@@ -0,0 +1,45 @@
import { dispatch } from "./src/dispatch.js";
import { CliError, errorMessage } from "./src/core/errors.js";
import { failure } from "./src/core/output.js";
import { buildRuntime, parseGlobalArgs } from "./src/core/runtime.js";
let currentServer: string | null = null;
let currentRequestId: string | null = null;
async function main(): Promise<number> {
const { globals, rest } = parseGlobalArgs(process.argv.slice(2));
if (isHelpRequest(rest)) {
await dispatch(null, rest);
return 0;
}
const ctx = await buildRuntime(globals);
currentServer = ctx.server;
currentRequestId = ctx.requestId;
await dispatch(ctx, rest);
return 0;
}
function isHelpRequest(argv: string[]): boolean {
return argv.length === 0 || argv[0] === "help" || argv.includes("--help") || argv.at(-1) === "help";
}
try {
process.exitCode = await main();
} catch (error) {
if (error instanceof CliError) {
failure({
summary: error.summary,
code: error.code,
message: error.message,
retryable: error.retryable,
server: currentServer,
requestId: currentRequestId,
data: error.data,
nextCommands: error.nextCommands,
});
process.exitCode = error.exitCode;
} else {
failure({ summary: "CLI 执行失败", code: "UNHANDLED_ERROR", message: errorMessage(error), retryable: false });
process.exitCode = 1;
}
}