Rename IsHelpCommand to IsAdditionalHelpTopicCommand (#398)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fixes #393
authored by Albert Nigmatzianov · committed by Eric Paris · parent 24bb44a · Browse files · 5 files·+16 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+16 added−17 removed
- other:+16 added−17 removed
Provenance
- Commit
0960ff7- Tree
3a0db50- Author
Albert Nigmatzianov <albertnigma@gmail.com>- Committer
Eric Paris <eparis@redhat.com>- Parent
24bb44a
5 files changed+16 added−17 removed
modified:doc/man_docs.go+2 added-2 removed
47 unmodified lines48 if header == nil {49 header = &GenManHeader{}50 }51 for _, c := range cmd.Commands() {52- if !c.IsAvailableCommand() || c.IsHelpCommand() {52+ if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {53 continue54 }55 if err := GenManTreeFromOpts(c, opts); err != nil {56 return err158 unmodified lines215 }216 children := cmd.Commands()217 sort.Sort(byName(children))218 for _, c := range children {219- if !c.IsAvailableCommand() || c.IsHelpCommand() {219+ if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {220 continue221 }222 seealso := fmt.Sprintf("**%s-%s(%s)**", dashCommandName, c.Name(), header.Section)223 seealsos = append(seealsos, seealso)8 unmodified linesmodified:doc/md_docs.go+2 added-2 removed
117 unmodified lines118 children := cmd.Commands()119 sort.Sort(byName(children))120 121 for _, child := range children {122- if !child.IsAvailableCommand() || child.IsHelpCommand() {122+ if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() {123 continue124 }125 cname := name + " " + child.Name()126 link := cname + ".md"21 unmodified lines148 }149 150 func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error {151 for _, c := range cmd.Commands() {152- if !c.IsAvailableCommand() || c.IsHelpCommand() {152+ if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {153 continue154 }155 if err := GenMarkdownTreeCustom(c, dir, filePrepender, linkHandler); err != nil {156 return err19 unmodified linesmodified:doc/util.go+1 added-1 removed
25 unmodified lines26 if cmd.HasParent() {27 return true28 }29 for _, c := range cmd.Commands() {30- if !c.IsAvailableCommand() || c.IsHelpCommand() {30+ if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {31 continue32 }33 return true34 }17 unmodified linesmodified:doc/yaml_docs.go+2 added-2 removed
55 unmodified lines56 57 // GenYamlTreeCustom creates yaml structured ref files58 func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error {59 for _, c := range cmd.Commands() {60- if !c.IsAvailableCommand() || c.IsHelpCommand() {60+ if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {61 continue62 }63 if err := GenYamlTreeCustom(c, dir, filePrepender, linkHandler); err != nil {64 return err51 unmodified lines116 }117 children := cmd.Commands()118 sort.Sort(byName(children))119 for _, child := range children {120- if !child.IsAvailableCommand() || child.IsHelpCommand() {120+ if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() {121 continue122 }123 result = append(result, child.Name()+" - "+child.Short)124 }41 unmodified linesmodified:command.go+9 added-10 removed
354 unmodified lines355 356 Global Flags:357 {{.InheritedFlags.FlagUsages | trimRightSpace}}{{end}}{{if .HasHelpSubCommands}}358 359-Additional help topics:{{range .Commands}}{{if .IsHelpCommand}}359+Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}360 {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}361 362 Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}363 `656 unmodified lines1020 1021 return false1022 }1023 1024-// IsHelpCommand determines if a command is a 'help' command; a help command is1025-// determined by the fact that it is NOT runnable/hidden/deprecated, and has no1026-// sub commands that are runnable/hidden/deprecated.1027-func (c *Command) IsHelpCommand() bool {1028-1024+// IsAdditionalHelpTopicCommand determines if a command is an additional1025+// help topic command; additional help topic command is determined by the1026+// fact that it is NOT runnable/hidden/deprecated, and has no sub commands that1027+// are runnable/hidden/deprecated.1028+// Concrete example: https://github.com/spf13/cobra/issues/393#issuecomment-282741924.1029+func (c *Command) IsAdditionalHelpTopicCommand() bool {1030 // if a command is runnable, deprecated, or hidden it is not a 'help' command1031 if c.Runnable() || len(c.Deprecated) != 0 || c.Hidden {1032 return false1033 }1034 1035 // if any non-help sub commands are found, the command is not a 'help' command1036 for _, sub := range c.commands {1036- if !sub.IsHelpCommand() {1037+ if !sub.IsAdditionalHelpTopicCommand() {1038 return false1039 }1040 }1041 4 unmodified lines1046 // HasHelpSubCommands determines if a command has any available 'help' sub commands1047 // that need to be shown in the usage/help default template under 'additional help1048 // topics'.1049 func (c *Command) HasHelpSubCommands() bool {1049-1050 // return true on the first found available 'help' sub command1051 for _, sub := range c.commands {1052- if sub.IsHelpCommand() {1052+ if sub.IsAdditionalHelpTopicCommand() {1053 return true1054 }1055 }1056 3 unmodified lines1060 1061 // HasAvailableSubCommands determines if a command has available sub commands that1062 // need to be shown in the usage/help default template under 'available commands'.1063 func (c *Command) HasAvailableSubCommands() bool {1064-1064 // return true on the first found available (non deprecated/help/hidden)1065 // sub command1066 for _, sub := range c.commands {1067 if sub.IsAvailableCommand() {238 unmodified lines