Files
ai_academy/cli/cmd/coverage_helpers_test.go
T
runny 7ec21f35b0 chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
2026-11-16 18:12:23 +08:00

29 lines
827 B
Go

package cmd
import "github.com/spf13/cobra"
// eachLeafCommand invokes fn for every runnable leaf command (no real
// subcommands) in the tree rooted at root, skipping cobra's generated
// `completion`/`help` subtrees and hidden commands. Shared by the agent-help
// and dry-run coverage drift guards so they agree, byte-for-byte, on what
// counts as a leaf.
func eachLeafCommand(root *cobra.Command, fn func(*cobra.Command)) {
exempt := map[string]bool{"completion": true, "help": true}
var walk func(c *cobra.Command)
walk = func(c *cobra.Command) {
realKids := 0
for _, k := range c.Commands() {
if exempt[k.Name()] || k.Hidden {
continue
}
realKids++
walk(k)
}
if c == root || realKids > 0 || exempt[c.Name()] {
return // group command or exempt — not a leaf
}
fn(c)
}
walk(root)
}