28
28
// Applied as annotations to workspace commands
29
29
// so they display in a separated "help" section.
30
30
workspaceCommand = map [string ]string {
31
- "workspaces" : " " ,
31
+ "workspaces" : "" ,
32
32
}
33
33
)
34
34
@@ -58,6 +58,20 @@ func init() {
58
58
cobra .AddTemplateFunc ("usageHeader" , func (s string ) string {
59
59
return header .Render (s )
60
60
})
61
+ cobra .AddTemplateFunc ("isWorkspaceCommand" , isWorkspaceCommand )
62
+ }
63
+
64
+ func isWorkspaceCommand (cmd * cobra.Command ) bool {
65
+ if _ , ok := cmd .Annotations ["workspaces" ]; ok {
66
+ return true
67
+ }
68
+ var ws bool
69
+ cmd .VisitParents (func (cmd * cobra.Command ) {
70
+ if _ , ok := cmd .Annotations ["workspaces" ]; ok {
71
+ ws = true
72
+ }
73
+ })
74
+ return ws
61
75
}
62
76
63
77
func Root () * cobra.Command {
@@ -335,8 +349,8 @@ func usageTemplate() string {
335
349
{{- if .HasAvailableSubCommands}}
336
350
{{usageHeader "Commands:"}}
337
351
{{- range .Commands}}
338
- {{- $hasRootAnnotations := (and $isRootHelp (gt (len .Annotations) 0 ))}}
339
- {{- if (or (and .IsAvailableCommand (not $hasRootAnnotations )) (eq .Name "help"))}}
352
+ {{- $isRootWorkspaceCommand := (and $isRootHelp (isWorkspaceCommand . ))}}
353
+ {{- if (or (and .IsAvailableCommand (not $isRootWorkspaceCommand )) (eq .Name "help"))}}
340
354
{{rpad .Name .NamePadding }} {{.Short}}
341
355
{{- end}}
342
356
{{- end}}
@@ -345,7 +359,7 @@ func usageTemplate() string {
345
359
{{- if (and $isRootHelp .HasAvailableSubCommands)}}
346
360
{{usageHeader "Workspace Commands:"}}
347
361
{{- range .Commands}}
348
- {{- if (and .IsAvailableCommand (ne (index .Annotations "workspaces") "" ))}}
362
+ {{- if (and .IsAvailableCommand (isWorkspaceCommand . ))}}
349
363
{{rpad .Name .NamePadding }} {{.Short}}
350
364
{{- end}}
351
365
{{- end}}
0 commit comments