summaryrefslogtreecommitdiffstats
path: root/commands/genman.go
diff options
context:
space:
mode:
authorAnthony Fok <foka@debian.org>2015-11-28 07:32:02 -0700
committerAnthony Fok <foka@debian.org>2015-11-28 07:32:02 -0700
commit50b5d0af29698f8866d55b8dac4da60276784d14 (patch)
treee67ce08b78bc25483737e9311280b151f3b60e03 /commands/genman.go
parent09379e893e2849cb7e86b0ea2f205e70b45a4b14 (diff)
Support setting target directory in `hugo gen man`
Fixes #1627
Diffstat (limited to 'commands/genman.go')
-rw-r--r--commands/genman.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/commands/genman.go b/commands/genman.go
index 1992628f0..3dc8d3f52 100644
--- a/commands/genman.go
+++ b/commands/genman.go
@@ -2,12 +2,15 @@ package commands
import (
"fmt"
+ "strings"
"github.com/spf13/cobra"
"github.com/spf13/hugo/helpers"
+ "github.com/spf13/hugo/hugofs"
jww "github.com/spf13/jwalterweatherman"
)
+var genmandir string
var genmanCmd = &cobra.Command{
Use: "man",
Short: "Generate man pages for the Hugo CLI",
@@ -16,15 +19,27 @@ 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()),
}
+ if !strings.HasSuffix(genmandir, helpers.FilePathSeparator) {
+ genmandir += helpers.FilePathSeparator
+ }
+ if found, _ := helpers.Exists(genmandir, hugofs.OsFs); !found {
+ jww.FEEDBACK.Println("Directory", genmandir, "does not exist, creating...")
+ hugofs.OsFs.MkdirAll(genmandir, 0777)
+ }
+ cmd.Root().DisableAutoGenTag = true
+
jww.FEEDBACK.Println("Generating Hugo man pages in", genmandir, "...")
cmd.Root().GenManTree(header, genmandir)
+
jww.FEEDBACK.Println("Done.")
},
}
+
+func init() {
+ genmanCmd.PersistentFlags().StringVar(&genmandir, "dir", "man/", "the directory to write the man pages.")
+}