getCommandName gets the cobra command name in the format `... parentCommandName commandName` by traversing it's parent commands recursively. until the root command is reached. Note: The root command's name is excluded. If cmd is the root cmd, return ""
(cmd *cobra.Command)
| 154 | // |
| 155 | // Note: The root command's name is excluded. If cmd is the root cmd, return "" |
| 156 | func getCommandName(cmd *cobra.Command) string { |
| 157 | fullCmdName := getFullCommandName(cmd) |
| 158 | _, after, ok := strings.Cut(fullCmdName, " ") |
| 159 | if !ok { |
| 160 | return "" |
| 161 | } |
| 162 | return after |
| 163 | } |
| 164 | |
| 165 | // getFullCommandName gets the full cobra command name in the format |
| 166 | // `... parentCommandName commandName` by traversing it's parent commands recursively |
searching dependent graphs…