Make markdown:generate annotation a markdown generation override for hidden commands

This commit is contained in:
Sam Coe 2020-11-04 12:35:08 +03:00
parent f770c6481c
commit 241e90aa9b
No known key found for this signature in database
GPG key ID: 8E322C20F811D086
5 changed files with 6 additions and 18 deletions

View file

@ -82,10 +82,9 @@ func GenMarkdownTree(cmd *cobra.Command, dir string) error {
// with custom filePrepender and linkHandler. // with custom filePrepender and linkHandler.
func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error { func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error {
for _, c := range cmd.Commands() { for _, c := range cmd.Commands() {
if genMarkdown, ok := c.Annotations["markdown:generate"]; ok { _, forceGeneration := c.Annotations["markdown:generate"]
if genMarkdown == "false" { if c.Hidden && !forceGeneration {
continue continue
}
} }
if err := GenMarkdownTreeCustom(c, dir, filePrepender, linkHandler); err != nil { if err := GenMarkdownTreeCustom(c, dir, filePrepender, linkHandler); err != nil {

View file

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

View file

@ -115,9 +115,6 @@ func NewCmdGarden(f *cmdutil.Factory, runF func(*GardenOptions) error) *cobra.Co
} }
return gardenRun(&opts) return gardenRun(&opts)
}, },
Annotations: map[string]string{
"markdown:generate": "false",
},
} }
return cmd return cmd

View file

@ -56,6 +56,7 @@ func NewHelpTopic(topic string) *cobra.Command {
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: helpTopicHelpFunc, Run: helpTopicHelpFunc,
Annotations: map[string]string{ Annotations: map[string]string{
"markdown:generate": "true",
"markdown:basename": "gh_help_" + topic, "markdown:basename": "gh_help_" + topic,
}, },
} }

View file

@ -16,9 +16,6 @@ func NewCmdVersion(f *cmdutil.Factory, version, buildDate string) *cobra.Command
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprint(f.IOStreams.Out, Format(version, buildDate)) fmt.Fprint(f.IOStreams.Out, Format(version, buildDate))
}, },
Annotations: map[string]string{
"markdown:generate": "false",
},
} }
cmdutil.DisableAuthCheck(cmd) cmdutil.DisableAuthCheck(cmd)