mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
add RemoveGroup method for Command
This commit is contained in:
parent
dcb405a939
commit
5943edc0db
1 changed files with 24 additions and 0 deletions
24
command.go
24
command.go
|
@ -1311,6 +1311,30 @@ func (c *Command) AddGroup(groups ...*Group) {
|
|||
c.commandgroups = append(c.commandgroups, groups...)
|
||||
}
|
||||
|
||||
// RemoveGroup removes one or more command groups to this parent command.
|
||||
func (c *Command) RemoveGroup(groupIDs ...string) {
|
||||
// remove groups from commandgroups
|
||||
groups := []*Group{}
|
||||
main:
|
||||
for _, group := range c.commandgroups {
|
||||
for _, groupID := range groupIDs {
|
||||
if group.ID == groupID {
|
||||
continue main
|
||||
}
|
||||
}
|
||||
groups = append(groups, group)
|
||||
}
|
||||
c.commandgroups = groups
|
||||
// remove the groupID from the target commands
|
||||
for _, command := range c.commands {
|
||||
for _, groupID := range groupIDs {
|
||||
if command.GroupID == groupID {
|
||||
command.GroupID = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveCommand removes one or more commands from a parent command.
|
||||
func (c *Command) RemoveCommand(cmds ...*Command) {
|
||||
commands := []*Command{}
|
||||
|
|
Loading…
Reference in a new issue