From: Anthony Fok <foka@debian.org>
Date: Sun, 22 Nov 2015 16:19:54 +0000 (-0700)
Subject: Add commands/genman.go to autogenerate man pages
X-Git-Tag: v0.15~22
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=098a0c819af2575628690517f4bd40253d7436d7;p=brevno-suite%2Fhugo

Add commands/genman.go to autogenerate man pages

Fixes #1369
---

diff --git a/commands/genman.go b/commands/genman.go
new file mode 100644
index 00000000..1c8ec45a
--- /dev/null
+++ b/commands/genman.go
@@ -0,0 +1,30 @@
+package commands
+
+import (
+	"fmt"
+
+	"github.com/spf13/cobra"
+	"github.com/spf13/hugo/helpers"
+	jww "github.com/spf13/jwalterweatherman"
+)
+
+var genmanCmd = &cobra.Command{
+	Use:   "genman",
+	Short: "Generate man pages for the Hugo CLI",
+	Long: `This command automatically generates up-to-date man pages of Hugo's
+command-line interface.  By default, it creates the man page files
+in the "man" directory under the current directory.`,
+
+	Run: func(cmd *cobra.Command, args []string) {
+		genmandir := "man/"
+		cmd.Root().DisableAutoGenTag = true
+		header := &cobra.GenManHeader{
+			Section: "1",
+			Manual:  "Hugo Manual",
+			Source:  fmt.Sprintf("Hugo %s", helpers.HugoVersion()),
+		}
+		jww.FEEDBACK.Println("Generating Hugo man pages in", genmandir, "...")
+		cmd.Root().GenManTree(header, genmandir)
+		jww.FEEDBACK.Println("Done.")
+	},
+}
diff --git a/commands/hugo.go b/commands/hugo.go
index f579d4b8..28a6d43b 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -88,6 +88,7 @@ func AddCommands() {
 	HugoCmd.AddCommand(undraftCmd)
 	HugoCmd.AddCommand(genautocompleteCmd)
 	HugoCmd.AddCommand(gendocCmd)
+	HugoCmd.AddCommand(genmanCmd)
 	HugoCmd.AddCommand(importCmd)
 }