Skip to content

Commit

Permalink
Merge pull request #25640 from dims/fix-issue-7496
Browse files Browse the repository at this point in the history
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
  • Loading branch information
k8s-merge-robot authored Jul 7, 2016
2 parents 4d91f0f + 91f1636 commit 5fe54ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
30 changes: 30 additions & 0 deletions pkg/kubectl/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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())
Expand Down
4 changes: 1 addition & 3 deletions vendor/github.com/spf13/cobra/command.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5fe54ac

Please sign in to comment.