Skip to content
Myr

Update help template

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

The template had gotten out of control. It was basically unparsable. This does a little more work in functions and a little less in the template. Overall it should be basically the same. It might output the 'additional help topics' in a couple of fewer places, but I doubt people complain too much...

authored by Eric Paris · committed by Eric Paris · parent 8e12710 · Browse files · 1 file+31 added−23 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+31 added−23 removed

  • other:+31 added−23 removed

1 file+31 added−23 removed

modified:command.go+31 added-23 removed
257 unmodified lines
258 {{.NameAndAliases}}259{{end}}{{if .HasExample}}260261Examples:262{{ .Example }}263{{end}}{{ if .HasRunnableSubCommands}}262{{ .Example }}{{end}}{{ if .HasNonHelpSubCommands}}263265Available Commands: {{range .Commands}}{{if and (.Runnable) (not .Deprecated)}}266 {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}267{{end}}268{{ if .HasLocalFlags}}Flags:269{{.LocalFlags.FlagUsages}}{{end}}270{{ if .HasInheritedFlags}}Global Flags:271{{.InheritedFlags.FlagUsages}}{{end}}{{if or (.HasHelpSubCommands) (.HasRunnableSiblings)}}272Additional help topics:273{{if .HasHelpSubCommands}}{{range .Commands}}{{if and (not .Runnable) (not .Deprecated)}} {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasRunnableSiblings }}{{range .Parent.Commands}}{{if and (not .Runnable) (not .Deprecated)}}{{if not (eq .Name $cmd.Name) }}274 {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{end}}275{{end}}{{ if .HasSubCommands }}264Available Commands: {{range .Commands}}{{if (not .IsHelpCommand)}}265 {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasLocalFlags}}266267Flags:268{{.LocalFlags.FlagUsages}}{{end}}{{ if .HasInheritedFlags}}269270Global Flags:271{{.InheritedFlags.FlagUsages}}{{end}}{{if .HasHelpSubCommands}}272273Additional help topics: {{range .Commands}}{{if .IsHelpCommand}}274 {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}}{{end}}{{end}}{{ if .HasSubCommands }}275276Use "{{.CommandPath}} [command] --help" for more information about a command.277{{end}}`278 }279}
522 unmodified lines
802func (c *Command) HasSubCommands() bool {803 return len(c.commands) > 0804}805806func (c *Command) HasRunnableSiblings() bool {807 if !c.HasParent() {806func (c *Command) IsHelpCommand() bool {807 if c.Runnable() {808 return false809 }810 for _, sub := range c.parent.commands {811 if sub.Runnable() {812 return true810 for _, sub := range c.commands {811 if len(sub.Deprecated) != 0 {812 continue813 }814 if !sub.IsHelpCommand() {815 return false816 }817 }815 return false818 return true819}820821func (c *Command) HasHelpSubCommands() bool {822 for _, sub := range c.commands {820 if !sub.Runnable() {823 if len(sub.Deprecated) != 0 {824 continue825 }826 if sub.IsHelpCommand() {827 return true828 }829 }830 return false831}832827// Determine if the command has runnable children commands828func (c *Command) HasRunnableSubCommands() bool {833func (c *Command) HasNonHelpSubCommands() bool {834 for _, sub := range c.commands {830 if sub.Runnable() {835 if len(sub.Deprecated) != 0 {836 continue837 }838 if !sub.IsHelpCommand() {839 return true840 }841 }842 return false
183 unmodified lines