Skip to content

Commit

Permalink
Fixed Missing support for removing group spf13#1911
Browse files Browse the repository at this point in the history
  • Loading branch information
valllabh committed Feb 15, 2023
1 parent a516d41 commit bfb4804
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit bfb4804

Please sign in to comment.