Skip to content

Commit

Permalink
add error check to RemoveGroup command
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Sep 1, 2023
1 parent 08be2cb commit 02094ac
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -1357,6 +1362,7 @@ main:
c.resetCompletionCommandGroupID()
}
}
return nil
}

// RemoveCommand removes one or more commands from a parent command.
Expand Down

0 comments on commit 02094ac

Please sign in to comment.