Much improved usage message

This commit is contained in:
spf13 2013-09-13 00:09:28 -04:00
parent 8858462331
commit b0c5461629

View file

@ -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}}{{if gt .Parent.Commands 1 }}{{range .Parent.Commands}}{{if .Runnable}}{{if not (eq .Name $cmd.Name) }}{{end}}
{{.CommandPath | printf "%-11s"}} :: {{.Short}}{{end}}{{end}}{{end}} {{.CommandPath | printf "%-11s"}} :: {{.Short}}{{end}}{{end}}{{end}}
Use "{{.Commander.Name}} help [topic]" for more information about that topic.
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)