Some fixes related to help command (#394)

* Add dots in the end of docs

* Make UsageTemplate show help command

Fix #366

* Fix output of help if it's invalid command
This commit is contained in:
Albert Nigmatzianov 2017-03-01 00:17:48 +05:00 committed by Eric Paris
parent 92ea23a837
commit fcd0c5a1df

View file

@ -155,12 +155,12 @@ func (c *Command) SetUsageTemplate(s string) {
} }
// SetFlagErrorFunc sets a function to generate an error when flag parsing // SetFlagErrorFunc sets a function to generate an error when flag parsing
// fails // fails.
func (c *Command) SetFlagErrorFunc(f func(*Command, error) error) { func (c *Command) SetFlagErrorFunc(f func(*Command, error) error) {
c.flagErrorFunc = f c.flagErrorFunc = f
} }
// SetHelpFunc sets help function. Can be defined by Application // SetHelpFunc sets help function. Can be defined by Application.
func (c *Command) SetHelpFunc(f func(*Command, []string)) { func (c *Command) SetHelpFunc(f func(*Command, []string)) {
c.helpFunc = f c.helpFunc = f
} }
@ -187,7 +187,7 @@ func (c *Command) SetGlobalNormalizationFunc(n func(f *flag.FlagSet, name string
} }
} }
// OutOrStdout returns output to stdout // OutOrStdout returns output to stdout.
func (c *Command) OutOrStdout() io.Writer { func (c *Command) OutOrStdout() io.Writer {
return c.getOut(os.Stdout) return c.getOut(os.Stdout)
} }
@ -347,7 +347,7 @@ Aliases:
Examples: Examples:
{{ .Example }}{{end}}{{if .HasAvailableSubCommands}} {{ .Example }}{{end}}{{if .HasAvailableSubCommands}}
Available Commands:{{range .Commands}}{{if .IsAvailableCommand}} Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
Flags: Flags:
@ -696,7 +696,6 @@ func (c *Command) Execute() error {
// ExecuteC executes the command. // ExecuteC executes the command.
func (c *Command) ExecuteC() (cmd *Command, err error) { func (c *Command) ExecuteC() (cmd *Command, err error) {
// Regardless of what command execute is called on, run on Root only // Regardless of what command execute is called on, run on Root only
if c.HasParent() { if c.HasParent() {
return c.Root().ExecuteC() return c.Root().ExecuteC()
@ -781,7 +780,7 @@ func (c *Command) initHelpCmd() {
Run: func(c *Command, args []string) { Run: func(c *Command, args []string) {
cmd, _, e := c.Root().Find(args) cmd, _, e := c.Root().Find(args)
if cmd == nil || e != nil { if cmd == nil || e != nil {
c.Printf("Unknown help topic %#q.", args) c.Printf("Unknown help topic %#q\n", args)
c.Root().Usage() c.Root().Usage()
} else { } else {
cmd.Help() cmd.Help()