Skip to content
Myr

New "example" section of commands

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

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.

authored by Eric Paris · committed by spf13 · parent a16cb24 · Browse files · 1 file+11 added−2 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+11 added−2 removed

  • other:+11 added−2 removed

1 file+11 added−2 removed

modified:command.go+11 added-2 removed
38 unmodified lines
39 // The short description shown in the 'help' output.40 Short string41 // The long message shown in the 'help <this-command>' output.42 Long string43 // Examples of how to use the command44 Example string45 // Full set of flags46 flags *flag.FlagSet47 // Set of flags childrens of this command will inherit48 pflags *flag.FlagSet
158 unmodified lines
207 {{.UseLine}}{{if .HasFlags}} [flags]{{end}}{{end}}{{if .HasSubCommands}}208 {{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}209210Aliases:209 {{.NameAndAliases}}{{end}}210{{ if .HasSubCommands}}211 {{.NameAndAliases}}212{{end}}{{if .HasExample}}213Examples:214{{ .Example }}215{{end}}{{ if .HasSubCommands}}216Available Commands: {{range .Commands}}{{if .Runnable}}217 {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}218{{end}}219{{ if .HasLocalFlags}}Flags:
468 unmodified lines
688func (c *Command) NameAndAliases() string {689 return strings.Join(append([]string{c.Name()}, c.Aliases...), ", ")690}691692func (c *Command) HasExample() bool {693 return len(c.Example) > 0694}695696// Determine if the command is itself runnable697func (c *Command) Runnable() bool {698 return c.Run != nil699}
166 unmodified lines