feat: CLI 展示文本使用动态命令前缀

This commit is contained in:
2026-06-09 20:29:42 +08:00
parent ce00751585
commit 2feea7a74f
2 changed files with 80 additions and 31 deletions

View File

@@ -1,6 +1,7 @@
import { describe, it, expect } from "bun:test";
import { UsageError, ConfigError, InternalError } from "../../src/cli/errors.ts";
import { mapError } from "../../src/cli.ts";
import { DEFAULT_PREFIX } from "../../src/core/pm.ts";
describe("mapError", () => {
it("CliError 原样返回", () => {
@@ -15,7 +16,7 @@ describe("mapError", () => {
const result = mapError(err);
expect(result).toBeInstanceOf(UsageError);
expect(result.message).toBe("未知选项: --badflag");
expect(result.hint).toBe("运行 rune help 查看所有命令");
expect(result.hint).toBe(`运行 ${DEFAULT_PREFIX} help 查看所有命令`);
});
it("Unknown command 转为 UsageError", () => {
@@ -38,8 +39,8 @@ describe("mapError", () => {
const result = mapError(err);
expect(result).toBeInstanceOf(UsageError);
expect(result.message).toBe("命令 'plan' 缺少必填参数");
expect(result.usage).toBe("rune plan <change-name>");
expect(result.hint).toContain("rune help plan");
expect(result.usage).toBe(`${DEFAULT_PREFIX} plan <change-name>`);
expect(result.hint).toContain(`${DEFAULT_PREFIX} help plan`);
});
it("未知 Error 转为 InternalError", () => {