New "example" section of commands

We have a long and short description.  This adds an "Example" section.
Which can used to create better docs than putting it all in Long.
This commit is contained in:
Eric Paris 2015-02-12 18:12:07 -05:00 committed by spf13
parent a16cb24999
commit bf480fe628

View file

@ -40,6 +40,8 @@ type Command struct {
Short string
// The long message shown in the 'help <this-command>' output.
Long string
// Examples of how to use the command
Example string
// Full set of flags
flags *flag.FlagSet
// Set of flags childrens of this command will inherit
@ -206,8 +208,11 @@ Usage: {{if .Runnable}}
{{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}
Aliases:
{{.NameAndAliases}}{{end}}
{{ if .HasSubCommands}}
{{.NameAndAliases}}
{{end}}{{if .HasExample}}
Examples:
{{ .Example }}
{{end}}{{ if .HasSubCommands}}
Available Commands: {{range .Commands}}{{if .Runnable}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
{{end}}
@ -684,6 +689,10 @@ func (c *Command) NameAndAliases() string {
return strings.Join(append([]string{c.Name()}, c.Aliases...), ", ")
}
func (c *Command) HasExample() bool {
return len(c.Example) > 0
}
// Determine if the command is itself runnable
func (c *Command) Runnable() bool {
return c.Run != nil