Commit 5fe54ac9 authored by k8s-merge-robot's avatar k8s-merge-robot Committed by GitHub

Merge pull request #25640 from dims/fix-issue-7496

Automatic merge from submit-queue kubectl should print usage at the bottom Override the Usage: output using SetUsageTemplate. Just moved the strings in the template to make sure we print Usage: at the bottom of the output and not at the top. Fixes issue #7496
parents 4d91f0f7 91f16364
...@@ -180,6 +180,34 @@ __custom_func() { ...@@ -180,6 +180,34 @@ __custom_func() {
* serviceaccounts (aka 'sa') * serviceaccounts (aka 'sa')
* services (aka 'svc') * services (aka 'svc')
` `
usage_template = `{{if gt .Aliases 0}}
Aliases:
{{.NameAndAliases}}
{{end}}{{if .HasExample}}
Examples:
{{ .Example }}{{end}}{{ if .HasAvailableSubCommands}}
Available Commands:{{range .Commands}}{{if .IsAvailableCommand}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasLocalFlags}}
Flags:
{{.LocalFlags.FlagUsages | trimRightSpace}}{{end}}{{ if .HasInheritedFlags}}
Global Flags:
{{.InheritedFlags.FlagUsages | trimRightSpace}}{{end}}{{if .HasHelpSubCommands}}
Additional help topics:{{range .Commands}}{{if .IsHelpCommand}}
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}
Usage:{{if .Runnable}}
{{if .HasFlags}}{{appendIfNotPresent .UseLine "[flags]"}}{{else}}{{.UseLine}}{{end}}{{end}}{{ if .HasSubCommands }}
{{ .CommandPath}} [command]
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
`
help_template = `{{with or .Long .Short }}{{. | trim}}{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
) )
// NewKubectlCommand creates the `kubectl` command and its nested children. // NewKubectlCommand creates the `kubectl` command and its nested children.
...@@ -194,6 +222,8 @@ Find more information at https://github.com/kubernetes/kubernetes.`, ...@@ -194,6 +222,8 @@ Find more information at https://github.com/kubernetes/kubernetes.`,
Run: runHelp, Run: runHelp,
BashCompletionFunction: bash_completion_func, BashCompletionFunction: bash_completion_func,
} }
cmds.SetHelpTemplate(help_template)
cmds.SetUsageTemplate(usage_template)
f.BindFlags(cmds.PersistentFlags()) f.BindFlags(cmds.PersistentFlags())
f.BindExternalFlags(cmds.PersistentFlags()) f.BindExternalFlags(cmds.PersistentFlags())
......
...@@ -295,9 +295,7 @@ func (c *Command) HelpTemplate() string { ...@@ -295,9 +295,7 @@ func (c *Command) HelpTemplate() string {
if c.HasParent() { if c.HasParent() {
return c.parent.HelpTemplate() return c.parent.HelpTemplate()
} }
return `{{with or .Long .Short }}{{. | trim}} return `{{with or .Long .Short }}{{. | trim}}{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
} }
// Really only used when casting a command to a commander // Really only used when casting a command to a commander
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment