mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Much improved usage message
This commit is contained in:
parent
8858462331
commit
b0c5461629
1 changed files with 13 additions and 11 deletions
24
cobra.go
24
cobra.go
|
@ -102,19 +102,20 @@ func (c *Commander) SetOutput(output io.Writer) {
|
||||||
|
|
||||||
func (c *Commander) initTemplates() {
|
func (c *Commander) initTemplates() {
|
||||||
c.UsageTemplate = `{{ $cmd := . }}{{.CommandPath | printf "%-11s"}} :: {{.Short}}
|
c.UsageTemplate = `{{ $cmd := . }}{{.CommandPath | printf "%-11s"}} :: {{.Short}}
|
||||||
Usage:
|
Usage: {{if .Runnable}}
|
||||||
{{.UseLine}}{{if .HasSubCommands}} command{{end}}{{if .HasFlags}} [flags]{{end}}
|
{{.UseLine}}{{if .HasFlags}} [flags]{{end}}{{end}}{{if .HasSubCommands}}
|
||||||
|
{{ .CommandPath}} [command]{{end}}
|
||||||
{{ if .HasSubCommands}}
|
{{ if .HasSubCommands}}
|
||||||
The commands are:
|
Available Commands: {{range .Commands}}{{if .Runnable}}
|
||||||
{{range .Commands}}{{if .Runnable}}
|
{{.Use | printf "%-11s"}} :: {{.Short}}{{end}}{{end}}
|
||||||
{{.UseLine | printf "%-11s"}} {{.Short}}{{end}}{{end}}
|
|
||||||
Use "{{$.CommandPath}} help [command]" for more information about a command.
|
|
||||||
{{end}}
|
{{end}}
|
||||||
Additional help topics: {{if gt .Commands 0 }}
|
{{ if .HasFlags}} Available Flags:
|
||||||
{{range .Commands}}{{if not .Runnable}}{{.CommandPath | printf "%-11s"}} {{.Short}}{{end}}{{end}}{{end}}{{if gt .Parent.Commands 1 }}
|
{{.Flags.FlagUsages}}{{end}}
|
||||||
{{range .Parent.Commands}}{{if .Runnable}}{{if not (eq .Name $cmd.Name) }}{{end}}
|
Additional help topics: {{if gt .Commands 0 }}{{range .Commands}}{{if not .Runnable}}
|
||||||
{{.CommandPath | printf "%-11s"}} :: {{.Short}}{{end}}{{end}}{{end}}
|
{{.CommandPath | printf "%-11s"}} :: {{.Short}}{{end}}{{end}}{{end}}{{if gt .Parent.Commands 1 }}{{range .Parent.Commands}}{{if .Runnable}}{{if not (eq .Name $cmd.Name) }}{{end}}
|
||||||
Use "{{.Commander.Name}} help [topic]" for more information about that topic.
|
{{.CommandPath | printf "%-11s"}} :: {{.Short}}{{end}}{{end}}{{end}}
|
||||||
|
|
||||||
|
Use "{{.Commander.Name}} help [command]" for more information about that command.
|
||||||
`
|
`
|
||||||
|
|
||||||
c.HelpTemplate = `{{if .Runnable}}Usage: {{.ProgramName}} {{.UsageLine}}
|
c.HelpTemplate = `{{if .Runnable}}Usage: {{.ProgramName}} {{.UsageLine}}
|
||||||
|
@ -375,6 +376,7 @@ func (c *Command) PersistentFlags() *flag.FlagSet {
|
||||||
// Intended for use in testing
|
// Intended for use in testing
|
||||||
func (c *Command) ResetFlags() {
|
func (c *Command) ResetFlags() {
|
||||||
c.flagErrorBuf = new(bytes.Buffer)
|
c.flagErrorBuf = new(bytes.Buffer)
|
||||||
|
c.flagErrorBuf.Reset()
|
||||||
c.flags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
c.flags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||||
c.flags.SetOutput(c.flagErrorBuf)
|
c.flags.SetOutput(c.flagErrorBuf)
|
||||||
c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||||
|
|
Loading…
Reference in a new issue