addCommandIfNotExists adds cmdToAdd to rootCmd if a command with the same name does not already exist.
(rootCmd *cobra.Command, cmdToAdd *cobra.Command)
| 229 | |
| 230 | // addCommandIfNotExists adds cmdToAdd to rootCmd if a command with the same name does not already exist. |
| 231 | func addCommandIfNotExists(rootCmd *cobra.Command, cmdToAdd *cobra.Command) { |
| 232 | for _, existingCmd := range rootCmd.Commands() { |
| 233 | if existingCmd.Name() == cmdToAdd.Name() { |
| 234 | return |
| 235 | } |
| 236 | } |
| 237 | rootCmd.AddCommand(cmdToAdd) |
| 238 | } |