mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-28 13:01:52 +00:00
parent
e614d8a57c
commit
1157fef859
4 changed files with 61 additions and 67 deletions
|
@ -49,7 +49,6 @@ func init() {
|
||||||
|
|
||||||
func benchmark(cmd *cobra.Command, args []string) error {
|
func benchmark(cmd *cobra.Command, args []string) error {
|
||||||
cfgInit := func(c *commandeer) error {
|
cfgInit := func(c *commandeer) error {
|
||||||
c.Set("renderToMemory", renderToMemory)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
c, err := InitializeConfig(false, cfgInit, benchmarkCmd)
|
c, err := InitializeConfig(false, cfgInit, benchmarkCmd)
|
||||||
|
|
|
@ -143,42 +143,8 @@ func (c *commandeer) loadConfig(running bool) error {
|
||||||
initializeFlags(cmdV, cfg)
|
initializeFlags(cmdV, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if baseURL != "" {
|
|
||||||
cfg.Set("baseURL", baseURL)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(disableKinds) > 0 {
|
|
||||||
cfg.Set("disableKinds", disableKinds)
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg.Set("logI18nWarnings", logI18nWarnings)
|
|
||||||
|
|
||||||
if theme != "" {
|
|
||||||
cfg.Set("theme", theme)
|
|
||||||
}
|
|
||||||
|
|
||||||
if themesDir != "" {
|
|
||||||
cfg.Set("themesDir", themesDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
if destination != "" {
|
|
||||||
cfg.Set("publishDir", destination)
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg.Set("workingDir", dir)
|
cfg.Set("workingDir", dir)
|
||||||
|
|
||||||
if contentDir != "" {
|
|
||||||
cfg.Set("contentDir", contentDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
if layoutDir != "" {
|
|
||||||
cfg.Set("layoutDir", layoutDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cacheDir != "" {
|
|
||||||
cfg.Set("cacheDir", cacheDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +210,7 @@ func (c *commandeer) loadConfig(running bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheDir = config.GetString("cacheDir")
|
cacheDir := config.GetString("cacheDir")
|
||||||
if cacheDir != "" {
|
if cacheDir != "" {
|
||||||
if helpers.FilePathSeparator != cacheDir[len(cacheDir)-1:] {
|
if helpers.FilePathSeparator != cacheDir[len(cacheDir)-1:] {
|
||||||
cacheDir = cacheDir + helpers.FilePathSeparator
|
cacheDir = cacheDir + helpers.FilePathSeparator
|
||||||
|
|
|
@ -129,7 +129,6 @@ Complete documentation is available at http://gohugo.io/.`,
|
||||||
if buildWatch {
|
if buildWatch {
|
||||||
c.Set("disableLiveReload", true)
|
c.Set("disableLiveReload", true)
|
||||||
}
|
}
|
||||||
c.Set("renderToMemory", renderToMemory)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,31 +143,34 @@ Complete documentation is available at http://gohugo.io/.`,
|
||||||
|
|
||||||
var hugoCmdV *cobra.Command
|
var hugoCmdV *cobra.Command
|
||||||
|
|
||||||
|
type flagVals struct {
|
||||||
|
}
|
||||||
|
|
||||||
// Flags that are to be added to commands.
|
// Flags that are to be added to commands.
|
||||||
var (
|
var (
|
||||||
buildWatch bool
|
// TODO(bep) var vs string
|
||||||
logging bool
|
buildWatch bool
|
||||||
renderToMemory bool // for benchmark testing
|
logging bool
|
||||||
verbose bool
|
verbose bool
|
||||||
verboseLog bool
|
verboseLog bool
|
||||||
debug bool
|
debug bool
|
||||||
quiet bool
|
quiet bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gc bool
|
gc bool
|
||||||
baseURL string
|
baseURL string
|
||||||
cacheDir string
|
//cacheDir string
|
||||||
contentDir string
|
//contentDir string
|
||||||
layoutDir string
|
//layoutDir string
|
||||||
cfgFile string
|
cfgFile string
|
||||||
destination string
|
//destination string
|
||||||
logFile string
|
logFile string
|
||||||
theme string
|
//theme string
|
||||||
themesDir string
|
//themesDir string
|
||||||
source string
|
source string
|
||||||
logI18nWarnings bool
|
//logI18nWarnings bool
|
||||||
disableKinds []string
|
//disableKinds []string
|
||||||
)
|
)
|
||||||
|
|
||||||
// Execute adds all child commands to the root command HugoCmd and sets flags appropriately.
|
// Execute adds all child commands to the root command HugoCmd and sets flags appropriately.
|
||||||
|
@ -234,13 +236,13 @@ func initHugoBuildCommonFlags(cmd *cobra.Command) {
|
||||||
cmd.Flags().BoolP("buildFuture", "F", false, "include content with publishdate in the future")
|
cmd.Flags().BoolP("buildFuture", "F", false, "include content with publishdate in the future")
|
||||||
cmd.Flags().BoolP("buildExpired", "E", false, "include expired content")
|
cmd.Flags().BoolP("buildExpired", "E", false, "include expired content")
|
||||||
cmd.Flags().StringVarP(&source, "source", "s", "", "filesystem path to read files relative from")
|
cmd.Flags().StringVarP(&source, "source", "s", "", "filesystem path to read files relative from")
|
||||||
cmd.Flags().StringVarP(&contentDir, "contentDir", "c", "", "filesystem path to content directory")
|
cmd.Flags().StringP("contentDir", "c", "", "filesystem path to content directory")
|
||||||
cmd.Flags().StringVarP(&layoutDir, "layoutDir", "l", "", "filesystem path to layout directory")
|
cmd.Flags().StringP("layoutDir", "l", "", "filesystem path to layout directory")
|
||||||
cmd.Flags().StringVarP(&cacheDir, "cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/")
|
cmd.Flags().StringP("cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/")
|
||||||
cmd.Flags().BoolP("ignoreCache", "", false, "ignores the cache directory")
|
cmd.Flags().BoolP("ignoreCache", "", false, "ignores the cache directory")
|
||||||
cmd.Flags().StringVarP(&destination, "destination", "d", "", "filesystem path to write files to")
|
cmd.Flags().StringP("destination", "d", "", "filesystem path to write files to")
|
||||||
cmd.Flags().StringVarP(&theme, "theme", "t", "", "theme to use (located in /themes/THEMENAME/)")
|
cmd.Flags().StringP("theme", "t", "", "theme to use (located in /themes/THEMENAME/)")
|
||||||
cmd.Flags().StringVarP(&themesDir, "themesDir", "", "", "filesystem path to themes directory")
|
cmd.Flags().StringP("themesDir", "", "", "filesystem path to themes directory")
|
||||||
cmd.Flags().Bool("uglyURLs", false, "(deprecated) if true, use /filename.html instead of /filename/")
|
cmd.Flags().Bool("uglyURLs", false, "(deprecated) if true, use /filename.html instead of /filename/")
|
||||||
cmd.Flags().Bool("canonifyURLs", false, "(deprecated) if true, all relative URLs will be canonicalized using baseURL")
|
cmd.Flags().Bool("canonifyURLs", false, "(deprecated) if true, all relative URLs will be canonicalized using baseURL")
|
||||||
cmd.Flags().StringVarP(&baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. http://spf13.com/")
|
cmd.Flags().StringVarP(&baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. http://spf13.com/")
|
||||||
|
@ -255,9 +257,9 @@ func initHugoBuildCommonFlags(cmd *cobra.Command) {
|
||||||
cmd.Flags().BoolP("forceSyncStatic", "", false, "copy all files when static is changed.")
|
cmd.Flags().BoolP("forceSyncStatic", "", false, "copy all files when static is changed.")
|
||||||
cmd.Flags().BoolP("noTimes", "", false, "don't sync modification time of files")
|
cmd.Flags().BoolP("noTimes", "", false, "don't sync modification time of files")
|
||||||
cmd.Flags().BoolP("noChmod", "", false, "don't sync permission mode of files")
|
cmd.Flags().BoolP("noChmod", "", false, "don't sync permission mode of files")
|
||||||
cmd.Flags().BoolVarP(&logI18nWarnings, "i18n-warnings", "", false, "print missing translations")
|
cmd.Flags().BoolP("i18n-warnings", "", false, "print missing translations")
|
||||||
|
|
||||||
cmd.Flags().StringSliceVar(&disableKinds, "disableKinds", []string{}, "disable different kind of pages (home, RSS etc.)")
|
cmd.Flags().StringSlice("disableKinds", []string{}, "disable different kind of pages (home, RSS etc.)")
|
||||||
|
|
||||||
// Set bash-completion.
|
// Set bash-completion.
|
||||||
// Each flag must first be defined before using the SetAnnotation() call.
|
// Each flag must first be defined before using the SetAnnotation() call.
|
||||||
|
@ -268,7 +270,7 @@ func initHugoBuildCommonFlags(cmd *cobra.Command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initBenchmarkBuildingFlags(cmd *cobra.Command) {
|
func initBenchmarkBuildingFlags(cmd *cobra.Command) {
|
||||||
cmd.Flags().BoolVar(&renderToMemory, "renderToMemory", false, "render to memory (only useful for benchmark testing)")
|
cmd.Flags().Bool("renderToMemory", false, "render to memory (only useful for benchmark testing)")
|
||||||
}
|
}
|
||||||
|
|
||||||
// init initializes flags.
|
// init initializes flags.
|
||||||
|
@ -349,7 +351,12 @@ func createLogger(cfg config.Provider) (*jww.Notepad, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeFlags(cmd *cobra.Command, cfg config.Provider) {
|
func initializeFlags(cmd *cobra.Command, cfg config.Provider) {
|
||||||
persFlagKeys := []string{"debug", "verbose", "logFile"}
|
persFlagKeys := []string{
|
||||||
|
"debug",
|
||||||
|
"verbose",
|
||||||
|
"logFile",
|
||||||
|
// Moved from vars
|
||||||
|
}
|
||||||
flagKeys := []string{
|
flagKeys := []string{
|
||||||
"cleanDestinationDir",
|
"cleanDestinationDir",
|
||||||
"buildDrafts",
|
"buildDrafts",
|
||||||
|
@ -367,6 +374,27 @@ func initializeFlags(cmd *cobra.Command, cfg config.Provider) {
|
||||||
"noChmod",
|
"noChmod",
|
||||||
"templateMetrics",
|
"templateMetrics",
|
||||||
"templateMetricsHints",
|
"templateMetricsHints",
|
||||||
|
|
||||||
|
// Moved from vars.
|
||||||
|
"baseURL ",
|
||||||
|
"buildWatch",
|
||||||
|
"cacheDir",
|
||||||
|
"cfgFile",
|
||||||
|
"contentDir",
|
||||||
|
"debug",
|
||||||
|
"destination",
|
||||||
|
"disableKinds",
|
||||||
|
"gc",
|
||||||
|
"layoutDir",
|
||||||
|
"logFile",
|
||||||
|
"logI18nWarnings",
|
||||||
|
"quiet",
|
||||||
|
"renderToMemory",
|
||||||
|
"source",
|
||||||
|
"theme",
|
||||||
|
"themesDir",
|
||||||
|
"verbose",
|
||||||
|
"verboseLog",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, key := range persFlagKeys {
|
for _, key := range persFlagKeys {
|
||||||
|
|
|
@ -116,6 +116,7 @@ var serverPorts []int
|
||||||
|
|
||||||
func server(cmd *cobra.Command, args []string) error {
|
func server(cmd *cobra.Command, args []string) error {
|
||||||
// If a Destination is provided via flag write to disk
|
// If a Destination is provided via flag write to disk
|
||||||
|
destination, _ := cmd.Flags().GetString("destination")
|
||||||
if destination != "" {
|
if destination != "" {
|
||||||
renderToDisk = true
|
renderToDisk = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue