feat: CLI 错误输出格式化

This commit is contained in:
2026-06-08 22:31:43 +08:00
parent dab63975f5
commit 50456188a0
2 changed files with 69 additions and 0 deletions

20
src/cli/output.ts Normal file
View File

@@ -0,0 +1,20 @@
import { CliError } from "./errors.ts";
export function formatError(error: CliError): string {
const parts: string[] = [`错误: ${error.message}`];
if (error.usage) {
parts.push(`用法: ${error.usage}`);
}
if (error.hint) {
parts.push(`提示: ${error.hint}`);
}
return parts.join("\n\n");
}
export function printError(error: CliError): never {
process.stderr.write(formatError(error) + "\n");
process.exit(1);
}