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:
parent
92ea23a837
commit
fcd0c5a1df
19
command.go
19
command.go
@ -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)
|
||||||
}
|
}
|
||||||
@ -345,19 +345,19 @@ Aliases:
|
|||||||
{{end}}{{if .HasExample}}
|
{{end}}{{if .HasExample}}
|
||||||
|
|
||||||
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:
|
||||||
{{.LocalFlags.FlagUsages | trimRightSpace}}{{end}}{{ if .HasAvailableInheritedFlags}}
|
{{.LocalFlags.FlagUsages | trimRightSpace}}{{end}}{{if .HasAvailableInheritedFlags}}
|
||||||
|
|
||||||
Global Flags:
|
Global Flags:
|
||||||
{{.InheritedFlags.FlagUsages | trimRightSpace}}{{end}}{{if .HasHelpSubCommands}}
|
{{.InheritedFlags.FlagUsages | trimRightSpace}}{{end}}{{if .HasHelpSubCommands}}
|
||||||
|
|
||||||
Additional help topics:{{range .Commands}}{{if .IsHelpCommand}}
|
Additional help topics:{{range .Commands}}{{if .IsHelpCommand}}
|
||||||
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasAvailableSubCommands }}
|
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}
|
||||||
|
|
||||||
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
|
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
|
||||||
`
|
`
|
||||||
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user