From f453e878d4639dafc68a1ce97de21152187e52e0 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Mon, 29 Jun 2015 20:06:04 -0400 Subject: [PATCH] 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... --- command.go | 54 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/command.go b/command.go index e82fd887..74565c2b 100644 --- a/command.go +++ b/command.go @@ -259,20 +259,20 @@ Aliases: {{end}}{{if .HasExample}} Examples: -{{ .Example }} -{{end}}{{ if .HasRunnableSubCommands}} +{{ .Example }}{{end}}{{ if .HasNonHelpSubCommands}} + +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. {{end}}` } @@ -803,31 +803,39 @@ func (c *Command) HasSubCommands() bool { return len(c.commands) > 0 } -func (c *Command) HasRunnableSiblings() bool { - if !c.HasParent() { +func (c *Command) IsHelpCommand() bool { + if c.Runnable() { return false } - for _, sub := range c.parent.commands { - if sub.Runnable() { - return true + for _, sub := range c.commands { + if len(sub.Deprecated) != 0 { + continue + } + if !sub.IsHelpCommand() { + return false } } - return false + return true } func (c *Command) HasHelpSubCommands() bool { for _, sub := range c.commands { - if !sub.Runnable() { + if len(sub.Deprecated) != 0 { + continue + } + if sub.IsHelpCommand() { return true } } return false } -// Determine if the command has runnable children commands -func (c *Command) HasRunnableSubCommands() bool { +func (c *Command) HasNonHelpSubCommands() bool { for _, sub := range c.commands { - if sub.Runnable() { + if len(sub.Deprecated) != 0 { + continue + } + if !sub.IsHelpCommand() { return true } }