(cmd *cobra.Command)
| 243 | } |
| 244 | |
| 245 | func GroupedCommands(cmd *cobra.Command) []CommandGroup { |
| 246 | var res []CommandGroup |
| 247 | |
| 248 | for _, g := range cmd.Groups() { |
| 249 | var cmds []*cobra.Command |
| 250 | for _, c := range cmd.Commands() { |
| 251 | if c.GroupID == g.ID && c.IsAvailableCommand() { |
| 252 | cmds = append(cmds, c) |
| 253 | } |
| 254 | } |
| 255 | if len(cmds) > 0 { |
| 256 | res = append(res, CommandGroup{ |
| 257 | Title: g.Title, |
| 258 | Commands: cmds, |
| 259 | }) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | var cmds []*cobra.Command |
| 264 | for _, c := range cmd.Commands() { |
| 265 | if c.GroupID == "" && c.IsAvailableCommand() { |
| 266 | cmds = append(cmds, c) |
| 267 | } |
| 268 | } |
| 269 | if len(cmds) > 0 { |
| 270 | defaultGroupTitle := "Additional commands" |
| 271 | if len(cmd.Groups()) == 0 { |
| 272 | defaultGroupTitle = "Available commands" |
| 273 | } |
| 274 | res = append(res, CommandGroup{ |
| 275 | Title: defaultGroupTitle, |
| 276 | Commands: cmds, |
| 277 | }) |
| 278 | } |
| 279 | |
| 280 | return res |
| 281 | } |
| 282 | |
| 283 | // rpad adds padding to the right of a string. |
| 284 | func rpad(s string, padding int) string { |
no outgoing calls
no test coverage detected