findCommand recursively searches for a command by name in the command tree
(rootCmd *cobra.Command, name string)
| 287 | |
| 288 | // findCommand recursively searches for a command by name in the command tree |
| 289 | func findCommand(rootCmd *cobra.Command, name string) *cobra.Command { |
| 290 | // Check if the root command itself matches |
| 291 | if rootCmd.Name() == name { |
| 292 | return rootCmd |
| 293 | } |
| 294 | |
| 295 | // Search through all subcommands recursively |
| 296 | for _, cmd := range rootCmd.Commands() { |
| 297 | if cmd.Name() == name { |
| 298 | return cmd |
| 299 | } |
| 300 | // Recursively search in subcommands |
| 301 | if found := findCommand(cmd, name); found != nil { |
| 302 | return found |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | return nil |
| 307 | } |
| 308 | |
| 309 | // loadAllPlugins loads all plugins and registers their commands to the root command |
| 310 | func loadAllPlugins(rootCmd *cobra.Command) error { |