feat: CLI 错误输出格式化
This commit is contained in:
20
src/cli/output.ts
Normal file
20
src/cli/output.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user