From 02094ac5c550a0e94012e1321e2cee07101c56e4 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Fri, 1 Sep 2023 23:53:31 +0900 Subject: [PATCH] add error check to RemoveGroup command --- command.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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.