@@ -22,16 +22,18 @@ func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *p
2222 flags .StringVar (& opts .ConfigDir , "config" , cliconfig .Dir (), "Location of client config files" )
2323 opts .Common .InstallFlags (flags )
2424
25+ cobra .AddTemplateFunc ("add" , func (a , b int ) int { return a + b })
2526 cobra .AddTemplateFunc ("hasSubCommands" , hasSubCommands )
2627 cobra .AddTemplateFunc ("hasManagementSubCommands" , hasManagementSubCommands )
2728 cobra .AddTemplateFunc ("hasInvalidPlugins" , hasInvalidPlugins )
2829 cobra .AddTemplateFunc ("operationSubCommands" , operationSubCommands )
2930 cobra .AddTemplateFunc ("managementSubCommands" , managementSubCommands )
3031 cobra .AddTemplateFunc ("invalidPlugins" , invalidPlugins )
3132 cobra .AddTemplateFunc ("wrappedFlagUsages" , wrappedFlagUsages )
32- cobra .AddTemplateFunc ("commandVendor" , commandVendor )
33- cobra .AddTemplateFunc ("isFirstLevelCommand" , isFirstLevelCommand ) // is it an immediate sub-command of the root
33+ cobra .AddTemplateFunc ("vendorAndVersion" , vendorAndVersion )
3434 cobra .AddTemplateFunc ("invalidPluginReason" , invalidPluginReason )
35+ cobra .AddTemplateFunc ("isPlugin" , isPlugin )
36+ cobra .AddTemplateFunc ("decoratedName" , decoratedName )
3537
3638 rootCmd .SetUsageTemplate (usageTemplate )
3739 rootCmd .SetHelpTemplate (helpTemplate )
@@ -155,19 +157,23 @@ func wrappedFlagUsages(cmd *cobra.Command) string {
155157 return cmd .Flags ().FlagUsagesWrapped (width - 1 )
156158}
157159
158- func isFirstLevelCommand (cmd * cobra.Command ) bool {
159- return cmd .Parent () == cmd .Root ()
160+ func decoratedName (cmd * cobra.Command ) string {
161+ decoration := " "
162+ if isPlugin (cmd ) {
163+ decoration = "*"
164+ }
165+ return cmd .Name () + decoration
160166}
161167
162- func commandVendor (cmd * cobra.Command ) string {
163- width := 13
164- if v , ok := cmd . Annotations [ pluginmanager . CommandAnnotationPluginVendor ]; ok {
165- if len ( v ) > width - 2 {
166- v = v [: width - 3 ] + "…"
168+ func vendorAndVersion (cmd * cobra.Command ) string {
169+ if vendor , ok := cmd . Annotations [ pluginmanager . CommandAnnotationPluginVendor ]; ok && isPlugin ( cmd ) {
170+ version := ""
171+ if v , ok := cmd . Annotations [ pluginmanager . CommandAnnotationPluginVersion ]; ok && v != "" {
172+ version = ", " + v
167173 }
168- return fmt .Sprintf ("%-*s " , width , "(" + v + ")" )
174+ return fmt .Sprintf ("(%s%s) " , vendor , version )
169175 }
170- return strings . Repeat ( " " , width )
176+ return ""
171177}
172178
173179func managementSubCommands (cmd * cobra.Command ) []* cobra.Command {
@@ -230,7 +236,7 @@ Options:
230236Management Commands:
231237
232238{{- range managementSubCommands . }}
233- {{rpad .Name .NamePadding }} {{ if isFirstLevelCommand . }}{{commandVendor .}} {{ end }}{{.Short }}
239+ {{rpad (decoratedName .) (add .NamePadding 1)}}{{.Short }}{{ if isPlugin .}} {{vendorAndVersion . }}{{ end }}
234240{{- end}}
235241
236242{{- end}}
@@ -239,7 +245,7 @@ Management Commands:
239245Commands:
240246
241247{{- range operationSubCommands . }}
242- {{rpad .Name .NamePadding }} {{ if isFirstLevelCommand . }}{{commandVendor .}} {{ end }}{{.Short }}
248+ {{rpad (decoratedName .) (add .NamePadding 1)}}{{.Short }}{{ if isPlugin .}} {{vendorAndVersion . }}{{ end }}
243249{{- end}}
244250{{- end}}
245251
0 commit comments