Skip to content
Myr

Merge pull request #77 from eparis/additional-help-topics

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

Additional help topics

authored by Eric Paris · committed by Eric Paris · parents 29e27b1, fd10548 · Browse files · 1 file+34 added−3 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+34 added−3 removed

  • other:+34 added−3 removed

1 file+34 added−3 removed

modified:command.go+34 added-3 removed
221 unmodified lines
222{{end}}{{if .HasExample}}223224Examples:225{{ .Example }}226{{end}}{{ if .HasSubCommands}}226{{end}}{{ if .HasRunnableSubCommands}}227228Available Commands: {{range .Commands}}{{if .Runnable}}229 {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}230{{end}}231{{ if .HasLocalFlags}}Flags:232{{.LocalFlags.FlagUsages}}{{end}}233{{ if .HasInheritedFlags}}Global Flags:234{{.InheritedFlags.FlagUsages}}{{end}}{{if .HasParent}}{{if and (gt .Commands 0) (gt .Parent.Commands 1) }}235Additional help topics: {{if gt .Commands 0 }}{{range .Commands}}{{if not .Runnable}} {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if gt .Parent.Commands 1 }}{{range .Parent.Commands}}{{if .Runnable}}{{if not (eq .Name $cmd.Name) }}{{end}}234{{.InheritedFlags.FlagUsages}}{{end}}{{if or (.HasHelpSubCommands) (.HasRunnableSiblings)}}235Additional help topics: {{if .HasHelpSubCommands}}{{range .Commands}}{{if not .Runnable}} {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasRunnableSiblings }}{{range .Parent.Commands}}{{if .Runnable}}{{if not (eq .Name $cmd.Name) }}236 {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{end}}237{{end}}{{ if .HasSubCommands }}238Use "{{.Root.Name}} help [command]" for more information about a command.239{{end}}`
503 unmodified lines
743func (c *Command) HasSubCommands() bool {744 return len(c.commands) > 0745}746747func (c *Command) HasRunnableSiblings() bool {748 if !c.HasParent() {749 return false750 }751 for _, sub := range c.parent.commands {752 if sub.Runnable() {753 return true754 }755 }756 return false757}758759func (c *Command) HasHelpSubCommands() bool {760 for _, sub := range c.commands {761 if !sub.Runnable() {762 return true763 }764 }765 return false766}767768// Determine if the command has runnable children commands769func (c *Command) HasRunnableSubCommands() bool {770 for _, sub := range c.commands {771 if sub.Runnable() {772 return true773 }774 }775 return false776}777778// Determine if the command is a child command779func (c *Command) HasParent() bool {780 return c.parent != nil781}
165 unmodified lines