feat: 帮助信息中文化并把命令分组说明写直白
- 根命令增加简介与常用示例,分组标题由「disk 相关命令」改为用途说明 (如「磁盘与文件占用:查看哪个目录、哪个文件最占空间」) - cobra 固定文案改为中文:用法 / 可用的子命令 / 选项、[flags] → [选项]、 help for xxx → 显示帮助;completion 与 help 也改为中文说明 - disk usage 摘要改为「看哪个目录或文件最占空间」
This commit is contained in:
@@ -748,3 +748,55 @@ func readCalls(path string) []string {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func TestRootHelpIsChineseAndExplainsGroups(t *testing.T) {
|
||||
app, stdout, stderr := testApp(centos("docker"))
|
||||
if code := app.Execute(nil); code != 0 {
|
||||
t.Fatalf("exit code = %d, stderr=%s", code, stderr.String())
|
||||
}
|
||||
out := stdout.String()
|
||||
|
||||
// The framing cobra would otherwise print in English.
|
||||
for _, want := range []string{"用法:", "可用的子命令:", "选项:", "显示帮助"} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("root help missing %q:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
for _, unwanted := range []string{"Usage:", "Available Commands:", "Flags:", "help for ", "[flags]", "Help about any command"} {
|
||||
if strings.Contains(out, unwanted) {
|
||||
t.Errorf("root help still contains English %q:\n%s", unwanted, out)
|
||||
}
|
||||
}
|
||||
|
||||
// Every group is described in plain words instead of "<name> 相关命令".
|
||||
for _, want := range []string{
|
||||
"磁盘与文件占用",
|
||||
"网络与端口",
|
||||
"本机进程",
|
||||
"系统软件包",
|
||||
"Docker 容器与镜像管理",
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("root help missing group description %q:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
if strings.Contains(out, "相关命令") {
|
||||
t.Errorf("groups still use the vague \"相关命令\" wording:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupHelpIsChinese(t *testing.T) {
|
||||
app, stdout, stderr := testApp(centos("docker"))
|
||||
if code := app.Execute([]string{"disk"}); code != 0 {
|
||||
t.Fatalf("exit code = %d, stderr=%s", code, stderr.String())
|
||||
}
|
||||
out := stdout.String()
|
||||
for _, want := range []string{"磁盘与文件占用", "用法:", "可用的子命令:", "显示帮助", "kopsc disk --help"} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("group help missing %q:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
if strings.Contains(out, "help for ") {
|
||||
t.Errorf("group help still says \"help for\":\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user