@@ -39,6 +39,8 @@ type defaultFrontend struct {
3939
4040 groupCmds map [string ]* cobra.Command
4141 executableCmds map [string ]* cobra.Command
42+
43+ cmdCategories []* cobra.Group
4244}
4345
4446func NewDefaultFrontend (appCtx context.LauncherContext , rootCmd * cobra.Command , backend backend.Backend ) Frontend {
@@ -50,9 +52,24 @@ func NewDefaultFrontend(appCtx context.LauncherContext, rootCmd *cobra.Command,
5052 groupCmds : make (map [string ]* cobra.Command ),
5153 executableCmds : make (map [string ]* cobra.Command ),
5254 }
55+ // add all command categories
56+ if viper .GetBool (config .GROUP_HELP_BY_REGISTRY_KEY ) {
57+ frontend .RegisterCommandCategory ()
58+ }
5359 return frontend
5460}
5561
62+ func (self * defaultFrontend ) RegisterCommandCategory () {
63+ self .cmdCategories = []* cobra.Group {}
64+ for _ , source := range self .backend .AllPackageSources () {
65+ self .cmdCategories = append (self .cmdCategories , & cobra.Group {
66+ ID : source .Repo .Name (),
67+ Title : fmt .Sprintf ("Commands from '%s' registry" , source .Repo .Name ()),
68+ })
69+ }
70+ self .rootCmd .AddGroup (self .cmdCategories ... )
71+ }
72+
5673func (self * defaultFrontend ) AddUserCommands () {
5774 self .addGroupCommands ()
5875 self .addExecutableCommands ()
@@ -61,6 +78,7 @@ func (self *defaultFrontend) AddUserCommands() {
6178func (self * defaultFrontend ) addGroupCommands () {
6279 groups := self .backend .GroupCommands ()
6380 for _ , v := range groups {
81+ registryName := v .RepositoryID ()
6482 group := v .RuntimeGroup ()
6583 name := v .RuntimeName ()
6684 usage := strings .TrimSpace (fmt .Sprintf ("%s %s" ,
@@ -99,13 +117,18 @@ func (self *defaultFrontend) addGroupCommands() {
99117 self .processFlags (false , group , name , cmd , flags , exclusiveFlags , groupFlags )
100118
101119 self .groupCmds [v .RuntimeName ()] = cmd
120+
121+ if viper .GetBool (config .GROUP_HELP_BY_REGISTRY_KEY ) {
122+ cmd .GroupID = registryName
123+ }
102124 self .rootCmd .AddCommand (cmd )
103125 }
104126}
105127
106128func (self * defaultFrontend ) addExecutableCommands () {
107129 executables := self .backend .ExecutableCommands ()
108130 for _ , v := range executables {
131+ registryName := v .RepositoryID ()
109132 group := v .RuntimeGroup ()
110133 name := v .RuntimeName ()
111134 usage := strings .TrimSpace (fmt .Sprintf ("%s %s" ,
@@ -205,6 +228,9 @@ func (self *defaultFrontend) addExecutableCommands() {
205228 }
206229
207230 if v .RuntimeGroup () == "" {
231+ if viper .GetBool (config .GROUP_HELP_BY_REGISTRY_KEY ) {
232+ cmd .GroupID = registryName
233+ }
208234 self .rootCmd .AddCommand (cmd )
209235 } else {
210236 if group , exists := self .groupCmds [v .RuntimeGroup ()]; exists {
0 commit comments