mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	Cobra, the CLI commander in use in Hugo, has some long awaited improvements in the error handling department. This enables a more centralized error handling approach. This commit introduces that by changing all the command funcs to `RunE`: * The core part of the error logging, usage logging and `os.Exit(-1)` is now performed in one place and that one place only. * The usage text is now only shown on invalid arguments etc. (user errors) Fixes #1502
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
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",
 | 
						|
	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.`,
 | 
						|
 | 
						|
	RunE: func(cmd *cobra.Command, args []string) error {
 | 
						|
		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.")
 | 
						|
 | 
						|
		return nil
 | 
						|
	},
 | 
						|
}
 | 
						|
 | 
						|
func init() {
 | 
						|
	genmanCmd.PersistentFlags().StringVar(&genmandir, "dir", "man/", "the directory to write the man pages.")
 | 
						|
 | 
						|
	// For bash-completion
 | 
						|
	genmanCmd.PersistentFlags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})
 | 
						|
}
 |