Browse Source

Merge pull request #46871 from thaJeztah/less_cobra_customisation

cmd/dockerd: remove various cobra templating
Sebastiaan van Stijn 1 year ago
parent
commit
bb99b3f02e
1 changed files with 2 additions and 59 deletions
  1. 2 59
      cmd/dockerd/cobra.go

+ 2 - 59
cmd/dockerd/cobra.go

@@ -10,10 +10,6 @@ import (
 // SetupRootCommand sets default usage, help, and error handling for the
 // SetupRootCommand sets default usage, help, and error handling for the
 // root command.
 // root command.
 func SetupRootCommand(rootCmd *cobra.Command) {
 func SetupRootCommand(rootCmd *cobra.Command) {
-	cobra.AddTemplateFunc("hasSubCommands", hasSubCommands)
-	cobra.AddTemplateFunc("hasManagementSubCommands", hasManagementSubCommands)
-	cobra.AddTemplateFunc("operationSubCommands", operationSubCommands)
-	cobra.AddTemplateFunc("managementSubCommands", managementSubCommands)
 	cobra.AddTemplateFunc("wrappedFlagUsages", wrappedFlagUsages)
 	cobra.AddTemplateFunc("wrappedFlagUsages", wrappedFlagUsages)
 
 
 	rootCmd.SetUsageTemplate(usageTemplate)
 	rootCmd.SetUsageTemplate(usageTemplate)
@@ -42,24 +38,6 @@ func FlagErrorFunc(cmd *cobra.Command, err error) error {
 	}
 	}
 }
 }
 
 
-func hasSubCommands(cmd *cobra.Command) bool {
-	return len(operationSubCommands(cmd)) > 0
-}
-
-func hasManagementSubCommands(cmd *cobra.Command) bool {
-	return len(managementSubCommands(cmd)) > 0
-}
-
-func operationSubCommands(cmd *cobra.Command) []*cobra.Command {
-	var cmds []*cobra.Command
-	for _, sub := range cmd.Commands() {
-		if sub.IsAvailableCommand() && !sub.HasSubCommands() {
-			cmds = append(cmds, sub)
-		}
-	}
-	return cmds
-}
-
 func wrappedFlagUsages(cmd *cobra.Command) string {
 func wrappedFlagUsages(cmd *cobra.Command) string {
 	width := 80
 	width := 80
 	if ws, err := term.GetWinsize(0); err == nil {
 	if ws, err := term.GetWinsize(0); err == nil {
@@ -68,20 +46,7 @@ func wrappedFlagUsages(cmd *cobra.Command) string {
 	return cmd.Flags().FlagUsagesWrapped(width - 1)
 	return cmd.Flags().FlagUsagesWrapped(width - 1)
 }
 }
 
 
-func managementSubCommands(cmd *cobra.Command) []*cobra.Command {
-	var cmds []*cobra.Command
-	for _, sub := range cmd.Commands() {
-		if sub.IsAvailableCommand() && sub.HasSubCommands() {
-			cmds = append(cmds, sub)
-		}
-	}
-	return cmds
-}
-
-var usageTemplate = `Usage:
-
-{{- if not .HasSubCommands}}	{{.UseLine}}{{end}}
-{{- if .HasSubCommands}}	{{ .CommandPath}} COMMAND{{end}}
+const usageTemplate = `Usage:	{{.UseLine}}
 
 
 {{ .Short | trim }}
 {{ .Short | trim }}
 
 
@@ -102,30 +67,8 @@ Examples:
 Options:
 Options:
 {{ wrappedFlagUsages . | trimRightSpace}}
 {{ wrappedFlagUsages . | trimRightSpace}}
 
 
-{{- end}}
-{{- if hasManagementSubCommands . }}
-
-Management Commands:
-
-{{- range managementSubCommands . }}
-  {{rpad .Name .NamePadding }} {{.Short}}
-{{- end}}
-
-{{- end}}
-{{- if hasSubCommands .}}
-
-Commands:
-
-{{- range operationSubCommands . }}
-  {{rpad .Name .NamePadding }} {{.Short}}
-{{- end}}
-{{- end}}
-
-{{- if .HasSubCommands }}
-
-Run '{{.CommandPath}} COMMAND --help' for more information on a command.
 {{- end}}
 {{- end}}
 `
 `
 
 
-var helpTemplate = `
+const helpTemplate = `
 {{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
 {{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`