AddGroup adds a group of commands to the parent command.
(parent *cobra.Command, title string, hidden bool, children ...*cobra.Command)
| 4 | |
| 5 | // AddGroup adds a group of commands to the parent command. |
| 6 | func AddGroup(parent *cobra.Command, title string, hidden bool, children ...*cobra.Command) { |
| 7 | // If the group is hidden, add the children directly to the parent. |
| 8 | if hidden { |
| 9 | for _, child := range children { |
| 10 | parent.AddCommand(child) |
| 11 | } |
| 12 | return |
| 13 | } |
| 14 | |
| 15 | group := &cobra.Group{ID: title, Title: title} |
| 16 | |
| 17 | // Add add the group to the parent command. |
| 18 | parent.AddGroup(group) |
| 19 | |
| 20 | // Add the child commands to the group. |
| 21 | for _, child := range children { |
| 22 | child.GroupID = title |
| 23 | parent.AddCommand(child) |
| 24 | } |
| 25 | } |