Skip to content

Commit 11a92cb

Browse files
committed
skip 'see also' sections for create plugins
On-behalf-of: @SAP [email protected]
1 parent daa2da3 commit 11a92cb

File tree

1 file changed

+25
-12
lines changed
  • hack/third_party/github.com/spf13/cobra/doc

1 file changed

+25
-12
lines changed

hack/third_party/github.com/spf13/cobra/doc/md_docs.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,31 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
7575

7676
if len(cmd.Example) > 0 {
7777
buf.WriteString("### Examples\n\n")
78-
fmt.Fprintf(buf, "```\n%s\n```\n\n", cmd.Example)
78+
fmt.Fprintf(buf, "```\n%s\n```\n\n", strings.TrimSpace(cmd.Example))
7979
}
8080

8181
if err := printOptions(buf, cmd, name); err != nil {
8282
return err
8383
}
8484
if hasSeeAlso(cmd) {
85-
buf.WriteString("### See Also\n\n")
85+
var links []string
86+
8687
if cmd.HasParent() {
8788
parent := cmd.Parent()
8889
pname := parent.CommandPath()
89-
link := pname + ".md"
90-
link = strings.ReplaceAll(link, " ", "_")
91-
fmt.Fprintf(buf, "* [%s](%s)\t - %s\n", pname, linkHandler(link), parent.Short)
92-
cmd.VisitParents(func(c *cobra.Command) {
93-
if c.DisableAutoGenTag {
94-
cmd.DisableAutoGenTag = c.DisableAutoGenTag
95-
}
96-
})
90+
91+
// skip "create" plugins
92+
if pname != "create" {
93+
link := pname + ".md"
94+
link = strings.ReplaceAll(link, " ", "_")
95+
links = append(links, fmt.Sprintf("* [%s](%s) – %s\n", pname, linkHandler(link), parent.Short))
96+
97+
cmd.VisitParents(func(c *cobra.Command) {
98+
if c.DisableAutoGenTag {
99+
cmd.DisableAutoGenTag = c.DisableAutoGenTag
100+
}
101+
})
102+
}
97103
}
98104

99105
children := cmd.Commands()
@@ -106,9 +112,16 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
106112
cname := name + " " + child.Name()
107113
link := cname + ".md"
108114
link = strings.ReplaceAll(link, " ", "_")
109-
fmt.Fprintf(buf, "* [%s](%s)\t - %s\n", cname, linkHandler(link), child.Short)
115+
links = append(links, fmt.Sprintf("* [%s](%s) – %s\n", cname, linkHandler(link), child.Short))
116+
}
117+
118+
if len(links) > 0 {
119+
buf.WriteString("### See Also\n\n")
120+
for _, link := range links {
121+
buf.WriteString(link)
122+
}
123+
buf.WriteString("\n")
110124
}
111-
buf.WriteString("\n")
112125
}
113126

114127
_, err := buf.WriteTo(w)

0 commit comments

Comments
 (0)