(cmd *cobra.Command)
| 258 | } |
| 259 | |
| 260 | func GroupedCommands(cmd *cobra.Command) []CommandGroup { |
| 261 | var res []CommandGroup |
| 262 | |
| 263 | for _, g := range cmd.Groups() { |
| 264 | var cmds []*cobra.Command |
| 265 | for _, c := range cmd.Commands() { |
| 266 | if c.GroupID == g.ID && c.IsAvailableCommand() { |
| 267 | cmds = append(cmds, c) |
| 268 | } |
| 269 | } |
| 270 | if len(cmds) > 0 { |
| 271 | res = append(res, CommandGroup{ |
| 272 | Title: g.Title, |
| 273 | Commands: cmds, |
| 274 | }) |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | var cmds []*cobra.Command |
| 279 | for _, c := range cmd.Commands() { |
| 280 | if c.GroupID == "" && c.IsAvailableCommand() { |
| 281 | cmds = append(cmds, c) |
| 282 | } |
| 283 | } |
| 284 | if len(cmds) > 0 { |
| 285 | defaultGroupTitle := "Additional commands" |
| 286 | if len(cmd.Groups()) == 0 { |
| 287 | defaultGroupTitle = "Available commands" |
| 288 | } |
| 289 | res = append(res, CommandGroup{ |
| 290 | Title: defaultGroupTitle, |
| 291 | Commands: cmds, |
| 292 | }) |
| 293 | } |
| 294 | |
| 295 | return res |
| 296 | } |
| 297 | |
| 298 | // rpad adds padding to the right of a string. |
| 299 | func rpad(s string, padding int) string { |
no outgoing calls
no test coverage detected