Fixed Missing support for removing group #1911

This commit is contained in:
vallabh 2023-02-15 09:45:25 +00:00
parent a516d4132c
commit bfb48042b2

View file

@ -1311,6 +1311,26 @@ func (c *Command) AddGroup(groups ...*Group) {
c.commandgroups = append(c.commandgroups, groups...) c.commandgroups = append(c.commandgroups, groups...)
} }
// RemoveGroup removes command group from parent command.
func (c *Command) RemoveGroup(group *Group) bool {
index := c.getGroupIndex(group.ID)
if index >= 0 {
c.commandgroups = append(c.commandgroups[:index], c.commandgroups[index+1:]...)
return true
}
return false
}
// getGroupIndex returns index of groupID if it exists in the list of command groups else -1.
func (c *Command) getGroupIndex(groupID string) int {
for index, x := range c.commandgroups {
if x.ID == groupID {
return index
}
}
return -1
}
// 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{}