From cd90af1646b39bf0e07132e17c18c9f8e970c3b4 Mon Sep 17 00:00:00 2001 From: andig Date: Thu, 20 Oct 2022 16:18:49 +0200 Subject: [PATCH] Keep BC --- command.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/command.go b/command.go index 297b40ae..269cfc0b 100644 --- a/command.go +++ b/command.go @@ -138,7 +138,7 @@ type Command struct { PersistentPostRunE func(cmd *Command, args []string) error // groups for subcommands - Groups []*Group + CommandGroups []*Group // args is actual args parsed from flags. args []string @@ -1244,6 +1244,11 @@ func (c *Command) AddCommand(cmds ...*Command) { } } +// Groups returns a slice of child command groups. +func (c *Command) Groups() []*Group { + return c.CommandGroups +} + // AllChildCommandsHaveGroup returns if all subcommands are assigned to a group func (c *Command) AllChildCommandsHaveGroup() bool { for _, sub := range c.commands { @@ -1256,7 +1261,7 @@ func (c *Command) AllChildCommandsHaveGroup() bool { // ContainGroups return if groupID exists in the list of command groups. func (c *Command) ContainsGroup(groupID string) bool { - for _, x := range c.Groups { + for _, x := range c.CommandGroups { if x.ID == groupID { return true } @@ -1266,7 +1271,7 @@ func (c *Command) ContainsGroup(groupID string) bool { // AddGroup adds one or more command groups to this parent command. func (c *Command) AddGroup(groups ...*Group) { - c.Groups = append(c.Groups, groups...) + c.CommandGroups = append(c.CommandGroups, groups...) } // RemoveCommand removes one or more commands from a parent command.