Skip to content
Myr

Some fixes related to help command (#394)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Add dots in the end of docs * Make UsageTemplate show help command Fix #366 * Fix output of help if it's invalid command

authored by Albert Nigmatzianov · committed by Eric Paris · parent 92ea23a · Browse files · 1 file+9 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−10 removed

  • other:+9 added−10 removed

1 file+9 added−10 removed

modified:command.go+9 added-10 removed
153 unmodified lines
154 c.usageTemplate = s155}156157// SetFlagErrorFunc sets a function to generate an error when flag parsing158// fails158// fails.159func (c *Command) SetFlagErrorFunc(f func(*Command, error) error) {160 c.flagErrorFunc = f161}162163// SetHelpFunc sets help function. Can be defined by Application163// SetHelpFunc sets help function. Can be defined by Application.164func (c *Command) SetHelpFunc(f func(*Command, []string)) {165 c.helpFunc = f166}167
18 unmodified lines
186 command.SetGlobalNormalizationFunc(n)187 }188}189190// OutOrStdout returns output to stdout190// OutOrStdout returns output to stdout.191func (c *Command) OutOrStdout() io.Writer {192 return c.getOut(os.Stdout)193}194
149 unmodified lines
344 {{.NameAndAliases}}345{{end}}{{if .HasExample}}346347Examples:348{{ .Example }}{{end}}{{ if .HasAvailableSubCommands}}348{{ .Example }}{{end}}{{if .HasAvailableSubCommands}}349350Available Commands:{{range .Commands}}{{if .IsAvailableCommand}}351 {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasAvailableLocalFlags}}350Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}351 {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}352353Flags:354{{.LocalFlags.FlagUsages | trimRightSpace}}{{end}}{{ if .HasAvailableInheritedFlags}}354{{.LocalFlags.FlagUsages | trimRightSpace}}{{end}}{{if .HasAvailableInheritedFlags}}355356Global Flags:357{{.InheritedFlags.FlagUsages | trimRightSpace}}{{end}}{{if .HasHelpSubCommands}}358359Additional help topics:{{range .Commands}}{{if .IsHelpCommand}}360 {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasAvailableSubCommands }}360 {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}361362Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}363`364}
330 unmodified lines
695}696697// ExecuteC executes the command.698func (c *Command) ExecuteC() (cmd *Command, err error) {699699 // Regardless of what command execute is called on, run on Root only700 if c.HasParent() {701 return c.Root().ExecuteC()702 }
76 unmodified lines
779780 Run: func(c *Command, args []string) {781 cmd, _, e := c.Root().Find(args)782 if cmd == nil || e != nil {784 c.Printf("Unknown help topic %#q.", args)783 c.Printf("Unknown help topic %#q\n", args)784 c.Root().Usage()785 } else {786 cmd.Help()787 }
519 unmodified lines