Skip to content

Commit 699c9ae

Browse files
committed
Remove Cobra autogenerated string from docs generation
1 parent 36949e2 commit 699c9ae

5 files changed

Lines changed: 5 additions & 63 deletions

File tree

cmd/gen-docs/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ func main() {
5555
header := &docs.GenManHeader{
5656
Title: "gh",
5757
Section: "1",
58-
Source: "", //source and manual are just put at the top of the manpage, before name
59-
Manual: "", //if source is an empty string, it's set to "Auto generated by spf13/cobra"
58+
Source: "",
59+
Manual: "",
6060
}
6161
err = docs.GenManTree(rootCmd, header, *dir)
6262
if err != nil {

internal/docs/man.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ type GenManTreeOptions struct {
7575

7676
// GenManHeader is a lot like the .TH header at the start of man pages. These
7777
// include the title, section, date, source, and manual. We will use the
78-
// current time if Date is unset and will use "Auto generated by spf13/cobra"
79-
// if the Source is unset.
78+
// current time if Date is unset.
8079
type GenManHeader struct {
8180
Title string
8281
Section string
@@ -92,7 +91,7 @@ func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {
9291
if header == nil {
9392
header = &GenManHeader{}
9493
}
95-
if err := fillHeader(header, cmd.CommandPath(), cmd.DisableAutoGenTag); err != nil {
94+
if err := fillHeader(header, cmd.CommandPath()); err != nil {
9695
return err
9796
}
9897

@@ -101,7 +100,7 @@ func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {
101100
return err
102101
}
103102

104-
func fillHeader(header *GenManHeader, name string, disableAutoGen bool) error {
103+
func fillHeader(header *GenManHeader, name string) error {
105104
if header.Title == "" {
106105
header.Title = strings.ToUpper(strings.Replace(name, " ", "\\-", -1))
107106
}
@@ -120,9 +119,6 @@ func fillHeader(header *GenManHeader, name string, disableAutoGen bool) error {
120119
header.Date = &now
121120
}
122121
header.date = (*header.Date).Format("Jan 2006")
123-
if header.Source == "" && !disableAutoGen {
124-
header.Source = "Auto generated by spf13/cobra"
125-
}
126122
return nil
127123
}
128124

@@ -208,11 +204,6 @@ func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
208204
dashParentPath := strings.Replace(parentPath, " ", "-", -1)
209205
seealso := fmt.Sprintf("**%s(%s)**", dashParentPath, header.Section)
210206
seealsos = append(seealsos, seealso)
211-
cmd.VisitParents(func(c *cobra.Command) {
212-
if c.DisableAutoGenTag {
213-
cmd.DisableAutoGenTag = c.DisableAutoGenTag
214-
}
215-
})
216207
}
217208
children := cmd.Commands()
218209
sort.Sort(byName(children))
@@ -225,8 +216,5 @@ func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
225216
}
226217
buf.WriteString(strings.Join(seealsos, ", ") + "\n")
227218
}
228-
if !cmd.DisableAutoGenTag {
229-
buf.WriteString(fmt.Sprintf("# HISTORY\n%s Auto generated by spf13/cobra\n", header.Date.Format("2-Jan-2006")))
230-
}
231219
return buf.Bytes()
232220
}

internal/docs/man_test.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ func TestGenManDoc(t *testing.T) {
4444
checkStringContains(t, output, translate(rootCmd.Name()))
4545
checkStringContains(t, output, translate(echoSubCmd.Name()))
4646
checkStringOmits(t, output, translate(deprecatedCmd.Name()))
47-
checkStringContains(t, output, translate("Auto generated"))
4847
}
4948

5049
func TestGenManNoHiddenParents(t *testing.T) {
@@ -79,32 +78,9 @@ func TestGenManNoHiddenParents(t *testing.T) {
7978
checkStringContains(t, output, translate(rootCmd.Name()))
8079
checkStringContains(t, output, translate(echoSubCmd.Name()))
8180
checkStringOmits(t, output, translate(deprecatedCmd.Name()))
82-
checkStringContains(t, output, translate("Auto generated"))
8381
checkStringOmits(t, output, "OPTIONS INHERITED FROM PARENT COMMANDS")
8482
}
8583

86-
func TestGenManNoGenTag(t *testing.T) {
87-
echoCmd.DisableAutoGenTag = true
88-
defer func() { echoCmd.DisableAutoGenTag = false }()
89-
90-
header := &GenManHeader{
91-
Title: "Project",
92-
Section: "2",
93-
}
94-
95-
// We generate on a subcommand so we have both subcommands and parents
96-
buf := new(bytes.Buffer)
97-
if err := GenMan(echoCmd, header, buf); err != nil {
98-
t.Fatal(err)
99-
}
100-
output := buf.String()
101-
102-
unexpected := translate("#HISTORY")
103-
checkStringOmits(t, output, unexpected)
104-
unexpected = translate("Auto generated by spf13/cobra")
105-
checkStringOmits(t, output, unexpected)
106-
}
107-
10884
func TestGenManSeeAlso(t *testing.T) {
10985
rootCmd := &cobra.Command{Use: "root", Run: emptyRun}
11086
aCmd := &cobra.Command{Use: "aaa", Run: emptyRun, Hidden: true} // #229

internal/docs/markdown.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"path/filepath"
99
"sort"
1010
"strings"
11-
"time"
1211

1312
"github.com/spf13/cobra"
1413
)
@@ -72,11 +71,6 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
7271
link := pname + ".md"
7372
link = strings.Replace(link, " ", "_", -1)
7473
buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", pname, linkHandler(link), parent.Short))
75-
cmd.VisitParents(func(c *cobra.Command) {
76-
if c.DisableAutoGenTag {
77-
cmd.DisableAutoGenTag = c.DisableAutoGenTag
78-
}
79-
})
8074
}
8175

8276
children := cmd.Commands()
@@ -93,9 +87,6 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
9387
}
9488
buf.WriteString("\n")
9589
}
96-
if !cmd.DisableAutoGenTag {
97-
buf.WriteString("###### Auto generated by spf13/cobra on " + time.Now().Format("2-Jan-2006") + "\n")
98-
}
9990
_, err := buf.WriteTo(w)
10091
return err
10192
}

internal/docs/markdown_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,6 @@ func TestGenMdNoHiddenParents(t *testing.T) {
6565
checkStringOmits(t, output, "Options inherited from parent commands")
6666
}
6767

68-
func TestGenMdNoTag(t *testing.T) {
69-
rootCmd.DisableAutoGenTag = true
70-
defer func() { rootCmd.DisableAutoGenTag = false }()
71-
72-
buf := new(bytes.Buffer)
73-
if err := GenMarkdown(rootCmd, buf); err != nil {
74-
t.Fatal(err)
75-
}
76-
output := buf.String()
77-
78-
checkStringOmits(t, output, "Auto generated")
79-
}
80-
8168
func TestGenMdTree(t *testing.T) {
8269
c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}
8370
tmpdir, err := ioutil.TempDir("", "test-gen-md-tree")

0 commit comments

Comments
 (0)