Skip to content
Myr

Man pages won't have auto gen tag when option is disabled (#1104)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Man pages wont have auto gen tag when option is disabled - this addresses #741 * Add documentation for doc generation and a changelog

authored by John McBride · committed by GitHub · parent 41fd44e · Browse files · 5 files+40 added−8 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+40 added−8 removed

  • other:+40 added−8 removed

5 files+40 added−8 removed

modified:doc/man_docs_test.go+2 added
99 unmodified lines
100 output := buf.String()101102 unexpected := translate("#HISTORY")103 checkStringOmits(t, output, unexpected)104 unexpected = translate("Auto generated by spf13/cobra")105 checkStringOmits(t, output, unexpected)106}107108func TestGenManSeeAlso(t *testing.T) {109 rootCmd := &cobra.Command{Use: "root", Run: emptyRun}
106 unmodified lines
modified:doc/man_docs.go+3 added-3 removed
103 unmodified lines
104func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {105 if header == nil {106 header = &GenManHeader{}107 }108 if err := fillHeader(header, cmd.CommandPath()); err != nil {108 if err := fillHeader(header, cmd.CommandPath(), cmd.DisableAutoGenTag); err != nil {109 return err110 }111112 b := genMan(cmd, header)113 _, err := w.Write(md2man.Render(b))114 return err115}116117func fillHeader(header *GenManHeader, name string) error {117func fillHeader(header *GenManHeader, name string, disableAutoGen bool) error {118 if header.Title == "" {119 header.Title = strings.ToUpper(strings.Replace(name, " ", "\\-", -1))120 }121 if header.Section == "" {
10 unmodified lines
132 }133 header.Date = &now134 }135 header.date = (*header.Date).Format("Jan 2006")136 if header.Source == "" {136 if header.Source == "" && !disableAutoGen {137 header.Source = "Auto generated by spf13/cobra"138 }139 return nil140}
107 unmodified lines
added:doc/README.md+12 added
added:CHANGELOG.md+22 added
modified:README.md+1 added-5 removed
716 unmodified lines
717```718719## Generating documentation for your command720721Cobra can generate documentation based on subcommands, flags, etc. in the following formats:721Cobra can generate documentation based on subcommands, flags, etc. Read more about it in the [docs generation documentation](doc/README.md).722723- [Markdown](doc/md_docs.md)724- [ReStructured Text](doc/rest_docs.md)725- [Man Page](doc/man_docs.md)726723## Generating bash completions724725Cobra can generate a bash-completion file. If you add more information to your command, these completions can be amazingly powerful and flexible. Read more about it in [Bash Completions](bash_completions.md).726
18 unmodified lines