mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
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:
commit
5fe54ac9ef
@ -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())
|
||||
|
4
vendor/github.com/spf13/cobra/command.go
generated
vendored
4
vendor/github.com/spf13/cobra/command.go
generated
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user