feat: add semantic CLI exit codes

This commit is contained in:
gitea committed 2026-09-11 17:11:51 +08:00
1 parent 45eb83a609
commit a5c0146c8d
5 files changed
+93 -10

No files matched your search

+11 -4
View File
@@ -1,6 +1,7 @@
import { VERSION } from "../version.js";
import { parseArgs, stringOption, booleanOption, outputOptions } from "./parser.js";
import { printHelp, printJson, redactSensitiveText } from "./printer.js";
import { classifyCliError } from "./errors.js";
import { initCorpRuntime } from "./helpers.js";
import { handleAuthCommand } from "./commands/auth.js";
import { handleCorpsCommand } from "./commands/corps.js";
@@ -279,17 +280,23 @@ async function dispatchCli(
}
} catch (error) {
const errorMsg = redactSensitiveText(error instanceof Error ? error.message : String(error));
const classification = classifyCliError(error);
if (jsonMode) {
return {
stdout: printJson({ error: true, message: errorMsg }),
stdout: JSON.stringify({
error: true,
message: errorMsg,
exitCode: classification.exitCode,
...(classification.nextAction ? { nextAction: classification.nextAction } : {}),
}, null, 2),
stderr: "",
exitCode: 1,
exitCode: classification.exitCode,
};
}
return {
stdout: "",
stderr: `[ERROR] ${errorMsg}\n`,
exitCode: 1,
stderr: `[ERROR] ${errorMsg}${classification.nextAction ? `\n下一步: ${classification.nextAction}` : ""}\n`,
exitCode: classification.exitCode,
};
}
}