(cmd *cobra.Command, prefix string)
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func walkCommands(cmd *cobra.Command, prefix string) []map[string]any { |
| 38 | var result []map[string]any |
| 39 | |
| 40 | for _, child := range cmd.Commands() { |
| 41 | if child.Hidden || !child.IsAvailableCommand() { |
| 42 | continue |
| 43 | } |
| 44 | |
| 45 | path := prefix + child.Name() |
| 46 | |
| 47 | entry := map[string]any{ |
| 48 | "name": child.Name(), |
| 49 | "path": path, |
| 50 | "short": child.Short, |
| 51 | } |
| 52 | |
| 53 | if notes, ok := child.Annotations["agent_notes"]; ok { |
| 54 | entry["agent_notes"] = notes |
| 55 | } |
| 56 | if usage, ok := child.Annotations[compatibilityUsageAnnotation]; ok { |
| 57 | entry["compatibility_usage"] = usage |
| 58 | } |
| 59 | |
| 60 | var flags []map[string]string |
| 61 | child.NonInheritedFlags().VisitAll(func(f *pflag.Flag) { |
| 62 | flags = append(flags, map[string]string{ |
| 63 | "name": f.Name, |
| 64 | "shorthand": f.Shorthand, |
| 65 | "usage": f.Usage, |
| 66 | "default": f.DefValue, |
| 67 | }) |
| 68 | }) |
| 69 | if len(flags) > 0 { |
| 70 | entry["flags"] = flags |
| 71 | } |
| 72 | |
| 73 | subs := walkCommands(child, path+" ") |
| 74 | if len(subs) > 0 { |
| 75 | entry["subcommands"] = subs |
| 76 | } |
| 77 | |
| 78 | result = append(result, entry) |
| 79 | } |
| 80 | |
| 81 | return result |
no outgoing calls
no test coverage detected