mirror of https://github.com/spf13/cobra.git
add RemoveGroup method for Command
This commit is contained in:
parent
dcb405a939
commit
5943edc0db
24
command.go
24
command.go
|
@ -1311,6 +1311,30 @@ func (c *Command) AddGroup(groups ...*Group) {
|
||||||
c.commandgroups = append(c.commandgroups, groups...)
|
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.
|
// RemoveCommand removes one or more commands from a parent command.
|
||||||
func (c *Command) RemoveCommand(cmds ...*Command) {
|
func (c *Command) RemoveCommand(cmds ...*Command) {
|
||||||
commands := []*Command{}
|
commands := []*Command{}
|
||||||
|
|
Loading…
Reference in New Issue