From bfb48042b2a2f1c1b327c3e10fbfb27fcec842e5 Mon Sep 17 00:00:00 2001 From: vallabh Date: Wed, 15 Feb 2023 09:45:25 +0000 Subject: [PATCH] Fixed Missing support for removing group #1911 --- command.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/command.go b/command.go index b6e3f4a1..08b274be 100644 --- a/command.go +++ b/command.go @@ -1311,6 +1311,26 @@ func (c *Command) AddGroup(groups ...*Group) { 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. func (c *Command) RemoveCommand(cmds ...*Command) { commands := []*Command{}