@@ -223,6 +223,10 @@ func NewBrevCommand() *cobra.Command { //nolint:funlen,gocognit,gocyclo // defin
223223 cobra .AddTemplateFunc ("workspaceCommands" , workspaceCommands )
224224 cobra .AddTemplateFunc ("hasProviderDependentCommands" , hasProviderDependentCommands )
225225 cobra .AddTemplateFunc ("providerDependentCommands" , providerDependentCommands )
226+ cobra .AddTemplateFunc ("hasRegisterCommands" , hasRegisterCommands )
227+ cobra .AddTemplateFunc ("registerCommands" , registerCommands )
228+ cobra .AddTemplateFunc ("subTreeCommands" , subTreeCommands )
229+ cobra .AddTemplateFunc ("isSubTreeCommand" , isSubTreeCommand )
226230 cobra .AddTemplateFunc ("hasAccessCommands" , hasAccessCommands )
227231 cobra .AddTemplateFunc ("accessCommands" , accessCommands )
228232 cobra .AddTemplateFunc ("hasOrganizationCommands" , hasOrganizationCommands )
@@ -287,7 +291,8 @@ func createCmdTree(cmd *cobra.Command, t *terminal.Terminal, loginCmdStore *stor
287291 cmd .AddCommand (reset .NewCmdReset (t , loginCmdStore , noLoginCmdStore ))
288292 cmd .AddCommand (profile .NewCmdProfile (t , loginCmdStore , noLoginCmdStore ))
289293 cmd .AddCommand (refresh .NewCmdRefresh (t , loginCmdStore ))
290- cmd .AddCommand (register .NewCmdRegister (t ))
294+ cmd .AddCommand (register .NewCmdRegister (t , loginCmdStore ))
295+ cmd .AddCommand (register .NewCmdUnregister (t , loginCmdStore ))
291296 cmd .AddCommand (runtasks .NewCmdRunTasks (t , noLoginCmdStore ))
292297 cmd .AddCommand (proxy .NewCmdProxy (t , noLoginCmdStore ))
293298 cmd .AddCommand (healthcheck .NewCmdHealthcheck (t , noLoginCmdStore ))
@@ -296,7 +301,6 @@ func createCmdTree(cmd *cobra.Command, t *terminal.Terminal, loginCmdStore *stor
296301 cmd .AddCommand (recreate .NewCmdRecreate (t , loginCmdStore ))
297302 cmd .AddCommand (writeconnectionevent .NewCmdwriteConnectionEvent (t , loginCmdStore ))
298303 cmd .AddCommand (updatemodel .NewCmdupdatemodel (t , loginCmdStore ))
299- // cmd.AddCommand(spark.NewCmdSpark(t, loginCmdStore, noLoginCmdStore))
300304}
301305
302306func hasWorkspaceCommands (cmd * cobra.Command ) bool {
@@ -327,6 +331,10 @@ func hasProviderDependentCommands(cmd *cobra.Command) bool {
327331 return len (providerDependentCommands (cmd )) > 0
328332}
329333
334+ func hasRegisterCommands (cmd * cobra.Command ) bool {
335+ return len (registerCommands (cmd )) > 0
336+ }
337+
330338func workspaceCommands (cmd * cobra.Command ) []* cobra.Command {
331339 cmds := []* cobra.Command {}
332340 for _ , sub := range cmd .Commands () {
@@ -397,6 +405,28 @@ func providerDependentCommands(cmd *cobra.Command) []*cobra.Command {
397405 return cmds
398406}
399407
408+ func registerCommands (cmd * cobra.Command ) []* cobra.Command {
409+ cmds := []* cobra.Command {}
410+ for _ , sub := range cmd .Commands () {
411+ if isRegisterCommand (sub ) {
412+ cmds = append (cmds , sub )
413+ }
414+ }
415+ return cmds
416+ }
417+
418+ // SubTreeCommands are commands that themselves have a tree of subcommands. Use of the 'sub-tree' annotation
419+ // will mark commands as this way, adding the 'Available Commands' section to the hep text.
420+ func subTreeCommands (cmd * cobra.Command ) []* cobra.Command {
421+ cmds := []* cobra.Command {}
422+ for _ , sub := range cmd .Commands () {
423+ if isSubTreeCommand (sub ) {
424+ cmds = append (cmds , sub )
425+ }
426+ }
427+ return cmds
428+ }
429+
400430func isWorkspaceCommand (cmd * cobra.Command ) bool {
401431 _ , ok := cmd .Annotations ["workspace" ]
402432 return ok
@@ -432,6 +462,16 @@ func isProviderDependentCommand(cmd *cobra.Command) bool {
432462 return ok
433463}
434464
465+ func isRegisterCommand (cmd * cobra.Command ) bool {
466+ _ , ok := cmd .Annotations ["register" ]
467+ return ok
468+ }
469+
470+ func isSubTreeCommand (cmd * cobra.Command ) bool {
471+ _ , ok := cmd .Annotations ["sub-tree" ]
472+ return ok
473+ }
474+
435475var usageTemplate = `Usage:{{if .Runnable}}
436476 {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
437477 {{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
@@ -490,8 +530,18 @@ Debug Commands:
490530 {{rpad .Name .NamePadding }} {{.Short}}
491531{{- end}}{{- end}}
492532
493- {{- end}}{{if .HasAvailableLocalFlags}}
533+ {{- end}}
534+
535+ {{- if hasRegisterCommands . }}
494536
537+ Register Commands:
538+ {{- range registerCommands . }}
539+ {{rpad .Name .NamePadding }} {{.Short}}
540+ {{- end}}{{- end}}
541+ {{if isSubTreeCommand . }}
542+ {{$cmds := .Commands}}Available Commands:{{range $cmds}}
543+ {{rpad .Name .NamePadding }} {{.Short}}
544+ {{- end}}{{- end}}{{if .HasAvailableLocalFlags}}
495545Flags:
496546{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}
497547
0 commit comments