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
This commit is contained in:
k8s-merge-robot 2016-07-06 20:19:18 -07:00 committed by GitHub
commit 5fe54ac9ef
2 changed files with 31 additions and 3 deletions

View File

@ -180,6 +180,34 @@ __custom_func() {
* serviceaccounts (aka 'sa')
* 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.
@ -194,6 +222,8 @@ Find more information at https://github.com/kubernetes/kubernetes.`,
Run: runHelp,
BashCompletionFunction: bash_completion_func,
}
cmds.SetHelpTemplate(help_template)
cmds.SetUsageTemplate(usage_template)
f.BindFlags(cmds.PersistentFlags())
f.BindExternalFlags(cmds.PersistentFlags())

View File

@ -295,9 +295,7 @@ func (c *Command) HelpTemplate() string {
if c.HasParent() {
return c.parent.HelpTemplate()
}
return `{{with or .Long .Short }}{{. | trim}}
{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
return `{{with or .Long .Short }}{{. | trim}}{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
}
// Really only used when casting a command to a commander