From 772bf462eedb662a105b2a7e39b2dd54bb31f558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E6=BE=9C?= Date: Tue, 4 Aug 2026 11:15:02 +0800 Subject: [PATCH] refactor(cli): relocate test-only walkLeafCommands to test helpers --- internal/cli/schema_orphan_helpers_test.go | 18 ++++++++++++++++++ internal/cli/schema_support.go | 17 ----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/internal/cli/schema_orphan_helpers_test.go b/internal/cli/schema_orphan_helpers_test.go index 9bccf379..e88fb6b3 100644 --- a/internal/cli/schema_orphan_helpers_test.go +++ b/internal/cli/schema_orphan_helpers_test.go @@ -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) + } +} diff --git a/internal/cli/schema_support.go b/internal/cli/schema_support.go index b1eeb7d3..578cc871 100644 --- a/internal/cli/schema_support.go +++ b/internal/cli/schema_support.go @@ -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