Repository: spf13/cobra
Pull request #1104 (2020-04-25 20:52:30)

Man pages won't have auto gen tag when option is disabled
This addresses https://github.com/spf13/cobra/issues/741

When `cmd.DisableAutoGenTag = true`, the man pages will no longer contain `Auto generated by spf13/cobra`

Let me know if this needs anything else!

jpmcb: I've added documentation for this in a new file `docs/README.md` which will also be viewable in Github when a user views the `docs/` folder in their browser. 

I've also added a changelog in a new file `CHANGELOG.md` which includes the v1.0.0 changes and captures this PRs new behavior in a `Pending` section. This should enable the maintainers to easily track changes, make releases, and request that contributors document their changes. 

If the `CHANGELOG.md` file is out of scope for this PR, I can remove it, let me know!

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..742d6d6
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,22 @@
+# Cobra Changelog
+
+## Pending
+* Fix man page doc generation - no auto generated tag when `cmd.DisableAutoGenTag = true` @jpmcb
+
+## v1.0.0
+Announcing v1.0.0 of Cobra. 🎉
+**Notable Changes**
+* Fish completion (including support for Go custom completion) @marckhouzam
+* API (urgent): Rename BashCompDirectives to ShellCompDirectives @marckhouzam
+* Remove/replace SetOutput on Command - deprecated @jpmcb
+* add support for autolabel stale PR @xchapter7x
+* Add Labeler Actions @xchapter7x
+* Custom completions coded in Go (instead of Bash) @marckhouzam
+* Partial Revert of #922 @jharshman
+* Add Makefile to project @jharshman
+* Correct documentation for InOrStdin @desponda
+* Apply formatting to templates @jharshman
+* Revert change so help is printed on stdout again @marckhouzam
+* Update md2man to v2.0.0 @pdf
+* update viper to v1.4.0 @umarcor
+* Update cmd/root.go example in README.md @jharshman
diff --git a/README.md b/README.md
index a371366..a932dd7 100644
--- a/README.md
+++ b/README.md
@@ -718,11 +718,7 @@ Run 'kubectl help' for usage.
 
 ## Generating documentation for your command
 
-Cobra can generate documentation based on subcommands, flags, etc. in the following formats:
-
-- [Markdown](doc/md_docs.md)
-- [ReStructured Text](doc/rest_docs.md)
-- [Man Page](doc/man_docs.md)
+Cobra can generate documentation based on subcommands, flags, etc. Read more about it in the [docs generation documentation](doc/README.md).
 
 ## Generating bash completions
 
diff --git a/doc/README.md b/doc/README.md
new file mode 100644
index 0000000..6ea4eb6
--- /dev/null
+++ b/doc/README.md
@@ -0,0 +1,12 @@
+# Documentation generation
+
+- [Man page docs](./man_docs.md)
+- [Markdown docs](./md_docs.md)
+- [Rest docs](./rest_docs.md)
+- [Yaml docs](./yaml_docs.md)
+
+## Options
+### `DisableAutoGenTag`
+You may set `cmd.DisableAutoGenTag = true`
+to _entirely_ remove the auto generated string "Auto generated by spf13/cobra..."
+from any documentation source.
diff --git a/doc/man_docs.go b/doc/man_docs.go
index 8c7fba4..b29a677 100644
--- a/doc/man_docs.go
+++ b/doc/man_docs.go
@@ -105,7 +105,7 @@ func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {
 	if header == nil {
 		header = &GenManHeader{}
 	}
-	if err := fillHeader(header, cmd.CommandPath()); err != nil {
+	if err := fillHeader(header, cmd.CommandPath(), cmd.DisableAutoGenTag); err != nil {
 		return err
 	}
 
@@ -114,7 +114,7 @@ func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {
 	return err
 }
 
-func fillHeader(header *GenManHeader, name string) error {
+func fillHeader(header *GenManHeader, name string, disableAutoGen bool) error {
 	if header.Title == "" {
 		header.Title = strings.ToUpper(strings.Replace(name, " ", "\\-", -1))
 	}
@@ -133,7 +133,7 @@ func fillHeader(header *GenManHeader, name string) error {
 		header.Date = &now
 	}
 	header.date = (*header.Date).Format("Jan 2006")
-	if header.Source == "" {
+	if header.Source == "" && !disableAutoGen {
 		header.Source = "Auto generated by spf13/cobra"
 	}
 	return nil


Test patch:
diff --git a/doc/man_docs_test.go b/doc/man_docs_test.go
index 2c400f5..ee9b875 100644
--- a/doc/man_docs_test.go
+++ b/doc/man_docs_test.go
@@ -101,6 +101,8 @@ func TestGenManNoGenTag(t *testing.T) {
 
 	unexpected := translate("#HISTORY")
 	checkStringOmits(t, output, unexpected)
+	unexpected = translate("Auto generated by spf13/cobra")
+	checkStringOmits(t, output, unexpected)
 }
 
 func TestGenManSeeAlso(t *testing.T) {