refactor(cli): relocate test-only walkLeafCommands to test helpers

This commit is contained in:
玉澜
2026-08-04 11:15:02 +08:00
parent 469d509cfb
commit 772bf462ee
2 changed files with 18 additions and 17 deletions
@@ -155,3 +155,21 @@ func runtimeCommandParameters(cmd *cobra.Command, canonicalPath string, pinnedPa
}
return parameters, nil
}
// walkLeafCommands invokes fn for every runnable leaf command in the tree.
// Test-only: production traversals use their own walkers.
func walkLeafCommands(cmd *cobra.Command, fn func(*cobra.Command)) {
if cmd.Runnable() && !cmd.HasSubCommands() {
fn(cmd)
return
}
for _, sub := range cmd.Commands() {
if sub.Name() == "help" {
continue
}
if !sub.IsAvailableCommand() && !hasRuntimeSchemaCommand(sub) {
continue
}
walkLeafCommands(sub, fn)
}
}
-17
View File
@@ -15,23 +15,6 @@ package cli
import "github.com/spf13/cobra"
// walkLeafCommands invokes fn for every runnable leaf command in the tree.
func walkLeafCommands(cmd *cobra.Command, fn func(*cobra.Command)) {
if cmd.Runnable() && !cmd.HasSubCommands() {
fn(cmd)
return
}
for _, sub := range cmd.Commands() {
if sub.Name() == "help" {
continue
}
if !sub.IsAvailableCommand() && !hasRuntimeSchemaCommand(sub) {
continue
}
walkLeafCommands(sub, fn)
}
}
func hasRuntimeSchemaCommand(cmd *cobra.Command) bool {
if cmd == nil {
return false