Skip to content
Myr

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

5 files+16 added−17 removed

modified:doc/man_docs.go+2 added-2 removed
47 unmodified lines
48 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 err
158 unmodified lines
215 }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 lines
modified:doc/md_docs.go+2 added-2 removed
117 unmodified lines
118 children := cmd.Commands()119 sort.Sort(byName(children))120121 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 lines
148}149150func 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 err
19 unmodified lines
modified:doc/util.go+1 added-1 removed
25 unmodified lines
26 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 lines
modified:doc/yaml_docs.go+2 added-2 removed
55 unmodified lines
5657// GenYamlTreeCustom creates yaml structured ref files58func 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 err
51 unmodified lines
116 }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 lines
modified:command.go+9 added-10 removed
354 unmodified lines
355356Global Flags:357{{.InheritedFlags.FlagUsages | trimRightSpace}}{{end}}{{if .HasHelpSubCommands}}358359Additional help topics:{{range .Commands}}{{if .IsHelpCommand}}359Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}360 {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}361362Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}363`
656 unmodified lines
10201021 return false1022}10231024// 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.1027func (c *Command) IsHelpCommand() bool {10281024// 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.1029func (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 }10341035 // 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 lines
1046// 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'.1049func (c *Command) HasHelpSubCommands() bool {10491050 // 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 lines
10601061// HasAvailableSubCommands determines if a command has available sub commands that1062// need to be shown in the usage/help default template under 'available commands'.1063func (c *Command) HasAvailableSubCommands() bool {10641064 // 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