Skip to content

Commit

Permalink
Support setting target directory in hugo gen man
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyfok committed Nov 28, 2015
1 parent 09379e8 commit 50b5d0a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions commands/genman.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.")
}

0 comments on commit 50b5d0a

Please sign in to comment.