@@ -18,7 +18,6 @@ import (
1818// Section Titles for Help Output
1919const (
2020 usage = "Usage"
21- corecmd = "Core commands"
2221 othercmd = "Other commands"
2322 helpcmd = "Help topics"
2423 flags = "Flags"
@@ -86,7 +85,7 @@ func displayHelp(cmd *cobra.Command, args []string) {
8685
8786// buildHelpEntries constructs a structured help message for a command.
8887func buildHelpEntries (cmd * cobra.Command ) []helpEntry {
89- var coreCommands , helpCommands , otherCommands []string
88+ var helpCommands , ungroupedCommands []string
9089 groupCommands := map [string ][]string {}
9190
9291 for _ , c := range cmd .Commands () {
@@ -95,24 +94,15 @@ func buildHelpEntries(cmd *cobra.Command) []helpEntry {
9594 }
9695
9796 entry := fmt .Sprintf ("%s%s" , rpad (c .Name (), c .NamePadding ()+ 3 ), c .Short )
98- if group , ok := c .Annotations ["group" ]; ok {
99- switch group {
100- case "core" :
101- coreCommands = append (coreCommands , entry )
102- case "help" :
103- helpCommands = append (helpCommands , entry )
104- default :
105- groupCommands [group ] = append (groupCommands [group ], entry )
106- }
107- } else {
108- otherCommands = append (otherCommands , entry )
109- }
110- }
11197
112- // Treat all commands as core if no groups are specified
113- if len (coreCommands ) == 0 && len (groupCommands ) == 0 {
114- coreCommands = otherCommands
115- otherCommands = []string {}
98+ switch c .GroupID {
99+ case "help" :
100+ helpCommands = append (helpCommands , entry )
101+ case "" :
102+ ungroupedCommands = append (ungroupedCommands , entry )
103+ default :
104+ groupCommands [c .GroupID ] = append (groupCommands [c .GroupID ], entry )
105+ }
116106 }
117107
118108 helpEntries := []helpEntry {}
@@ -121,14 +111,16 @@ func buildHelpEntries(cmd *cobra.Command) []helpEntry {
121111 }
122112
123113 helpEntries = append (helpEntries , helpEntry {usage , cmd .UseLine ()})
124- if len (coreCommands ) > 0 {
125- helpEntries = append (helpEntries , helpEntry {corecmd , strings .Join (coreCommands , "\n " )})
126- }
127- for group , cmds := range groupCommands {
128- helpEntries = append (helpEntries , helpEntry {fmt .Sprintf ("%s commands" , toTitle (group )), strings .Join (cmds , "\n " )})
129- }
130- if len (otherCommands ) > 0 {
131- helpEntries = append (helpEntries , helpEntry {othercmd , strings .Join (otherCommands , "\n " )})
114+ if len (ungroupedCommands ) > 0 && len (groupCommands ) == 0 {
115+ // No groups defined — show all commands under "Commands"
116+ helpEntries = append (helpEntries , helpEntry {"Commands" , strings .Join (ungroupedCommands , "\n " )})
117+ } else {
118+ for group , cmds := range groupCommands {
119+ helpEntries = append (helpEntries , helpEntry {fmt .Sprintf ("%s commands" , toTitle (group )), strings .Join (cmds , "\n " )})
120+ }
121+ if len (ungroupedCommands ) > 0 {
122+ helpEntries = append (helpEntries , helpEntry {othercmd , strings .Join (ungroupedCommands , "\n " )})
123+ }
132124 }
133125 if len (helpCommands ) > 0 {
134126 helpEntries = append (helpEntries , helpEntry {helpcmd , strings .Join (helpCommands , "\n " )})
0 commit comments