diff --git a/command.go b/command.go index cee74478..00853c9b 100644 --- a/command.go +++ b/command.go @@ -1325,18 +1325,23 @@ func (c *Command) AddGroup(groups ...*Group) { } // RemoveGroup removes one or more command groups to this parent command. -func (c *Command) RemoveGroup(groupIDs ...string) { +func (c *Command) RemoveGroup(groupIDs ...string) error { // remove groups from commandgroups groups := []*Group{} + hasRemoved := false main: for _, group := range c.commandgroups { for _, groupID := range groupIDs { if group.ID == groupID { + hasRemoved = true continue main } } groups = append(groups, group) } + if !hasRemoved { + return fmt.Errorf("following group ID does not exist; %s", strings.Join(groupIDs, ", ")) + } c.commandgroups = groups // remove the groupID from the target commands for _, command := range c.commands { @@ -1357,6 +1362,7 @@ main: c.resetCompletionCommandGroupID() } } + return nil } // RemoveCommand removes one or more commands from a parent command.