From 5943edc0dbf10562c6dbb838ca8deb2c5e3de0a7 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sun, 16 Jul 2023 19:43:22 +0900 Subject: [PATCH] add RemoveGroup method for Command --- command.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/command.go b/command.go index 01f7c6f..1f7ed92 100644 --- a/command.go +++ b/command.go @@ -1311,6 +1311,30 @@ func (c *Command) AddGroup(groups ...*Group) { c.commandgroups = append(c.commandgroups, groups...) } +// RemoveGroup removes one or more command groups to this parent command. +func (c *Command) RemoveGroup(groupIDs ...string) { + // remove groups from commandgroups + groups := []*Group{} +main: + for _, group := range c.commandgroups { + for _, groupID := range groupIDs { + if group.ID == groupID { + continue main + } + } + groups = append(groups, group) + } + c.commandgroups = groups + // remove the groupID from the target commands + for _, command := range c.commands { + for _, groupID := range groupIDs { + if command.GroupID == groupID { + command.GroupID = "" + } + } + } +} + // RemoveCommand removes one or more commands from a parent command. func (c *Command) RemoveCommand(cmds ...*Command) { commands := []*Command{}