refactor(cli): relocate test-only walkLeafCommands to test helpers
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user