This commit is contained in:
andig 2022-10-20 16:18:49 +02:00
parent 7aa995fd55
commit cd90af1646

View file

@ -138,7 +138,7 @@ type Command struct {
PersistentPostRunE func(cmd *Command, args []string) error PersistentPostRunE func(cmd *Command, args []string) error
// groups for subcommands // groups for subcommands
Groups []*Group CommandGroups []*Group
// args is actual args parsed from flags. // args is actual args parsed from flags.
args []string 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 // AllChildCommandsHaveGroup returns if all subcommands are assigned to a group
func (c *Command) AllChildCommandsHaveGroup() bool { func (c *Command) AllChildCommandsHaveGroup() bool {
for _, sub := range c.commands { 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. // ContainGroups return if groupID exists in the list of command groups.
func (c *Command) ContainsGroup(groupID string) bool { func (c *Command) ContainsGroup(groupID string) bool {
for _, x := range c.Groups { for _, x := range c.CommandGroups {
if x.ID == groupID { if x.ID == groupID {
return true return true
} }
@ -1266,7 +1271,7 @@ func (c *Command) ContainsGroup(groupID string) bool {
// AddGroup adds one or more command groups to this parent command. // AddGroup adds one or more command groups to this parent command.
func (c *Command) AddGroup(groups ...*Group) { 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. // RemoveCommand removes one or more commands from a parent command.