forked from mirror/cobra
Update help template
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...
This commit is contained in:
parent
8e127101ec
commit
f453e878d4
56
command.go
56
command.go
|
@ -259,20 +259,20 @@ Aliases:
|
||||||
{{end}}{{if .HasExample}}
|
{{end}}{{if .HasExample}}
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
{{ .Example }}
|
{{ .Example }}{{end}}{{ if .HasNonHelpSubCommands}}
|
||||||
{{end}}{{ if .HasRunnableSubCommands}}
|
|
||||||
|
Available Commands: {{range .Commands}}{{if (not .IsHelpCommand)}}
|
||||||
|
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasLocalFlags}}
|
||||||
|
|
||||||
|
Flags:
|
||||||
|
{{.LocalFlags.FlagUsages}}{{end}}{{ if .HasInheritedFlags}}
|
||||||
|
|
||||||
|
Global Flags:
|
||||||
|
{{.InheritedFlags.FlagUsages}}{{end}}{{if .HasHelpSubCommands}}
|
||||||
|
|
||||||
|
Additional help topics: {{range .Commands}}{{if .IsHelpCommand}}
|
||||||
|
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}}{{end}}{{end}}{{ if .HasSubCommands }}
|
||||||
|
|
||||||
Available Commands: {{range .Commands}}{{if and (.Runnable) (not .Deprecated)}}
|
|
||||||
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
|
||||||
{{end}}
|
|
||||||
{{ if .HasLocalFlags}}Flags:
|
|
||||||
{{.LocalFlags.FlagUsages}}{{end}}
|
|
||||||
{{ if .HasInheritedFlags}}Global Flags:
|
|
||||||
{{.InheritedFlags.FlagUsages}}{{end}}{{if or (.HasHelpSubCommands) (.HasRunnableSiblings)}}
|
|
||||||
Additional help topics:
|
|
||||||
{{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) }}
|
|
||||||
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{end}}
|
|
||||||
{{end}}{{ if .HasSubCommands }}
|
|
||||||
Use "{{.CommandPath}} [command] --help" for more information about a command.
|
Use "{{.CommandPath}} [command] --help" for more information about a command.
|
||||||
{{end}}`
|
{{end}}`
|
||||||
}
|
}
|
||||||
|
@ -803,31 +803,39 @@ func (c *Command) HasSubCommands() bool {
|
||||||
return len(c.commands) > 0
|
return len(c.commands) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) HasRunnableSiblings() bool {
|
func (c *Command) IsHelpCommand() bool {
|
||||||
if !c.HasParent() {
|
if c.Runnable() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, sub := range c.parent.commands {
|
for _, sub := range c.commands {
|
||||||
if sub.Runnable() {
|
if len(sub.Deprecated) != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !sub.IsHelpCommand() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Command) HasHelpSubCommands() bool {
|
func (c *Command) HasHelpSubCommands() bool {
|
||||||
for _, sub := range c.commands {
|
for _, sub := range c.commands {
|
||||||
if !sub.Runnable() {
|
if len(sub.Deprecated) != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if sub.IsHelpCommand() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if the command has runnable children commands
|
func (c *Command) HasNonHelpSubCommands() bool {
|
||||||
func (c *Command) HasRunnableSubCommands() bool {
|
|
||||||
for _, sub := range c.commands {
|
for _, sub := range c.commands {
|
||||||
if sub.Runnable() {
|
if len(sub.Deprecated) != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !sub.IsHelpCommand() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue