Skip to content

Commit f770c64

Browse files
committed
Generate markdown for help topics
1 parent c7ede29 commit f770c64

6 files changed

Lines changed: 25 additions & 2 deletions

File tree

cmd/gen-docs/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func main() {
3838

3939
io, _, _, _ := iostreams.Test()
4040
rootCmd := root.NewCmdRoot(&cmdutil.Factory{IOStreams: io}, "", "")
41+
rootCmd.InitDefaultHelpCmd()
4142

4243
err := os.MkdirAll(*dir, 0755)
4344
if err != nil {

internal/docs/markdown.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,22 @@ func GenMarkdownTree(cmd *cobra.Command, dir string) error {
8282
// with custom filePrepender and linkHandler.
8383
func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error {
8484
for _, c := range cmd.Commands() {
85-
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
86-
continue
85+
if genMarkdown, ok := c.Annotations["markdown:generate"]; ok {
86+
if genMarkdown == "false" {
87+
continue
88+
}
8789
}
90+
8891
if err := GenMarkdownTreeCustom(c, dir, filePrepender, linkHandler); err != nil {
8992
return err
9093
}
9194
}
9295

9396
basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".md"
97+
if override, ok := cmd.Annotations["markdown:basename"]; ok {
98+
basename = override + ".md"
99+
}
100+
94101
filename := filepath.Join(dir, basename)
95102
f, err := os.Create(filename)
96103
if err != nil {

pkg/cmd/repo/credits/credits.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ func NewCmdCredits(f *cmdutil.Factory, runF func(*CreditsOptions) error) *cobra.
6161
return creditsRun(opts)
6262
},
6363
Hidden: true,
64+
Annotations: map[string]string{
65+
"markdown:generate": "false",
66+
},
6467
}
6568

6669
cmd.Flags().BoolVarP(&opts.Static, "static", "s", false, "Print a static version of the credits")
@@ -104,6 +107,9 @@ func NewCmdRepoCredits(f *cmdutil.Factory, runF func(*CreditsOptions) error) *co
104107
return creditsRun(opts)
105108
},
106109
Hidden: true,
110+
Annotations: map[string]string{
111+
"markdown:generate": "false",
112+
},
107113
}
108114

109115
cmd.Flags().BoolVarP(&opts.Static, "static", "s", false, "Print a static version of the credits")

pkg/cmd/repo/garden/garden.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ func NewCmdGarden(f *cmdutil.Factory, runF func(*GardenOptions) error) *cobra.Co
115115
}
116116
return gardenRun(&opts)
117117
},
118+
Annotations: map[string]string{
119+
"markdown:generate": "false",
120+
},
118121
}
119122

120123
return cmd

pkg/cmd/root/help_topic.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ func NewHelpTopic(topic string) *cobra.Command {
5555
Hidden: true,
5656
Args: cobra.NoArgs,
5757
Run: helpTopicHelpFunc,
58+
Annotations: map[string]string{
59+
"markdown:basename": "gh_help_" + topic,
60+
},
5861
}
5962

6063
cmd.SetHelpFunc(helpTopicHelpFunc)

pkg/cmd/version/version.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ func NewCmdVersion(f *cmdutil.Factory, version, buildDate string) *cobra.Command
1616
Run: func(cmd *cobra.Command, args []string) {
1717
fmt.Fprint(f.IOStreams.Out, Format(version, buildDate))
1818
},
19+
Annotations: map[string]string{
20+
"markdown:generate": "false",
21+
},
1922
}
2023

2124
cmdutil.DisableAuthCheck(cmd)

0 commit comments

Comments
 (0)