]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
commands: Improve the common build flag handling
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 17 May 2023 16:45:23 +0000 (18:45 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 17 May 2023 20:13:29 +0000 (22:13 +0200)
Updates #10947

17 files changed:
commands/commandeer.go
commands/commands.go
commands/config.go
commands/convert.go
commands/gen.go
commands/import.go
commands/list.go
commands/mod.go
commands/new.go
commands/server.go
commands/xcommand_template.go
config/allconfig/allconfig.go
go.mod
go.sum
hugolib/content_map_page.go
testscripts/commands/server.txt [new file with mode: 0644]
testscripts/unfinished/server.txt [deleted file]

index 7e53189961c0f920abed5d7324856c3aabca14d9..e433e935af7388860d4d19ee3153df126a4c2820 100644 (file)
@@ -111,22 +111,6 @@ type rootCommand struct {
        environment string
 
        // Common build flags.
-       *buildFlags
-
-       // TODO(bep) var vs string
-       logging        bool
-       verbose        bool
-       verboseLog     bool
-       debug          bool
-       quiet          bool
-       renderToMemory bool
-
-       cfgFile string
-       cfgDir  string
-       logFile string
-}
-
-type buildFlags struct {
        baseURL         string
        gc              bool
        poll            string
@@ -139,6 +123,18 @@ type buildFlags struct {
        mutexprofile string
        traceprofile string
        printm       bool
+
+       // TODO(bep) var vs string
+       logging        bool
+       verbose        bool
+       verboseLog     bool
+       debug          bool
+       quiet          bool
+       renderToMemory bool
+
+       cfgFile string
+       cfgDir  string
+       logFile string
 }
 
 func (r *rootCommand) Build(cd *simplecobra.Commandeer, bcfg hugolib.BuildCfg, cfg config.Provider) (*hugolib.HugoSites, error) {
@@ -384,7 +380,7 @@ func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
        return nil
 }
 
-func (r *rootCommand) Init(cd, runner *simplecobra.Commandeer) error {
+func (r *rootCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        r.Out = os.Stdout
        if r.quiet {
                r.Out = io.Discard
@@ -463,7 +459,8 @@ func (r *rootCommand) IsTestRun() bool {
        return os.Getenv("HUGO_TESTRUN") != ""
 }
 
-func (r *rootCommand) WithCobraCommand(cmd *cobra.Command) error {
+func (r *rootCommand) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Use = "hugo [flags]"
        cmd.Short = "hugo builds your site"
        cmd.Long = `hugo is the main command, used to build your Hugo site.
@@ -503,7 +500,7 @@ Complete documentation is available at https://gohugo.io/.`
        _ = cmd.PersistentFlags().SetAnnotation("logFile", cobra.BashCompFilenameExt, []string{})
 
        // Configure local flags
-       applyLocalBuildFlags(cmd, r.buildFlags)
+       applyLocalBuildFlags(cmd, r)
 
        // Set bash-completion.
        // Each flag must first be defined before using the SetAnnotation() call.
@@ -512,7 +509,7 @@ Complete documentation is available at https://gohugo.io/.`
        return nil
 }
 
-func applyLocalBuildFlags(cmd *cobra.Command, f *buildFlags) {
+func applyLocalBuildFlags(cmd *cobra.Command, r *rootCommand) {
        cmd.Flags().Bool("cleanDestinationDir", false, "remove files from destination not found in static directories")
        cmd.Flags().BoolP("buildDrafts", "D", false, "include content marked as draft")
        cmd.Flags().BoolP("buildFuture", "F", false, "include content with publishdate in the future")
@@ -522,25 +519,25 @@ func applyLocalBuildFlags(cmd *cobra.Command, f *buildFlags) {
        cmd.Flags().StringP("cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/")
        cmd.Flags().BoolP("ignoreCache", "", false, "ignores the cache directory")
        cmd.Flags().StringSliceP("theme", "t", []string{}, "themes to use (located in /themes/THEMENAME/)")
-       cmd.Flags().StringVarP(&f.baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. https://spf13.com/")
+       cmd.Flags().StringVarP(&r.baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. https://spf13.com/")
        cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date, author, and CODEOWNERS info to the pages")
-       cmd.Flags().BoolVar(&f.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build")
-       cmd.Flags().StringVar(&f.poll, "poll", "", "set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes")
-       cmd.Flags().BoolVar(&f.panicOnWarning, "panicOnWarning", false, "panic on first WARNING log")
+       cmd.Flags().BoolVar(&r.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build")
+       cmd.Flags().StringVar(&r.poll, "poll", "", "set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes")
+       cmd.Flags().BoolVar(&r.panicOnWarning, "panicOnWarning", false, "panic on first WARNING log")
        cmd.Flags().Bool("templateMetrics", false, "display metrics about template executions")
        cmd.Flags().Bool("templateMetricsHints", false, "calculate some improvement hints when combined with --templateMetrics")
-       cmd.Flags().BoolVar(&f.forceSyncStatic, "forceSyncStatic", false, "copy all files when static is changed.")
+       cmd.Flags().BoolVar(&r.forceSyncStatic, "forceSyncStatic", false, "copy all files when static is changed.")
        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("noBuildLock", "", false, "don't create .hugo_build.lock file")
        cmd.Flags().BoolP("printI18nWarnings", "", false, "print missing translations")
        cmd.Flags().BoolP("printPathWarnings", "", false, "print warnings on duplicate target paths etc.")
        cmd.Flags().BoolP("printUnusedTemplates", "", false, "print warnings on unused templates.")
-       cmd.Flags().StringVarP(&f.cpuprofile, "profile-cpu", "", "", "write cpu profile to `file`")
-       cmd.Flags().StringVarP(&f.memprofile, "profile-mem", "", "", "write memory profile to `file`")
-       cmd.Flags().BoolVarP(&f.printm, "printMemoryUsage", "", false, "print memory usage to screen at intervals")
-       cmd.Flags().StringVarP(&f.mutexprofile, "profile-mutex", "", "", "write Mutex profile to `file`")
-       cmd.Flags().StringVarP(&f.traceprofile, "trace", "", "", "write trace to `file` (not useful in general)")
+       cmd.Flags().StringVarP(&r.cpuprofile, "profile-cpu", "", "", "write cpu profile to `file`")
+       cmd.Flags().StringVarP(&r.memprofile, "profile-mem", "", "", "write memory profile to `file`")
+       cmd.Flags().BoolVarP(&r.printm, "printMemoryUsage", "", false, "print memory usage to screen at intervals")
+       cmd.Flags().StringVarP(&r.mutexprofile, "profile-mutex", "", "", "write Mutex profile to `file`")
+       cmd.Flags().StringVarP(&r.traceprofile, "trace", "", "", "write trace to `file` (not useful in general)")
 
        // Hide these for now.
        cmd.Flags().MarkHidden("profile-cpu")
@@ -591,7 +588,8 @@ func (c *simpleCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
        return c.run(ctx, cd, c.rootCmd, args)
 }
 
-func (c *simpleCommand) WithCobraCommand(cmd *cobra.Command) error {
+func (c *simpleCommand) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Short = c.short
        cmd.Long = c.long
        if c.use != "" {
@@ -603,7 +601,7 @@ func (c *simpleCommand) WithCobraCommand(cmd *cobra.Command) error {
        return nil
 }
 
-func (c *simpleCommand) Init(cd, runner *simplecobra.Commandeer) error {
+func (c *simpleCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        c.rootCmd = cd.Root.Command.(*rootCommand)
        if c.initc != nil {
                return c.initc(cd)
index f90b09e0c00d93b8310c11ef26b135bec7c81dd7..9d707b8418994e6753b3044df34cce6fd1beeb9c 100644 (file)
@@ -20,7 +20,6 @@ import (
 // newExec wires up all of Hugo's CLI.
 func newExec() (*simplecobra.Exec, error) {
        rootCmd := &rootCommand{
-               buildFlags: &buildFlags{},
                commands: []simplecobra.Commander{
                        newVersionCmd(),
                        newEnvCommand(),
index 6f0a29b35ac93de76cc2f88755fc9de5f46d5dc6..80b869a287e17b01f86e62d5abfe77fd2fa4e085 100644 (file)
@@ -23,7 +23,6 @@ import (
        "github.com/gohugoio/hugo/modules"
        "github.com/gohugoio/hugo/parser"
        "github.com/gohugoio/hugo/parser/metadecoders"
-       "github.com/spf13/cobra"
 )
 
 // newConfigCommand creates a new config command and its subcommands.
@@ -68,13 +67,14 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
        return nil
 }
 
-func (c *configCommand) WithCobraCommand(cmd *cobra.Command) error {
+func (c *configCommand) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Short = "Print the site configuration"
        cmd.Long = `Print the site configuration, both default and custom settings.`
        return nil
 }
 
-func (c *configCommand) Init(cd, runner *simplecobra.Commandeer) error {
+func (c *configCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        c.r = cd.Root.Command.(*rootCommand)
        return nil
 }
@@ -176,12 +176,13 @@ func (c *configMountsCommand) Run(ctx context.Context, cd *simplecobra.Commandee
        return nil
 }
 
-func (c *configMountsCommand) WithCobraCommand(cmd *cobra.Command) error {
+func (c *configMountsCommand) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Short = "Print the configured file mounts"
        return nil
 }
 
-func (c *configMountsCommand) Init(cd, runner *simplecobra.Commandeer) error {
+func (c *configMountsCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        c.configCmd = cd.Parent.Command.(*configCommand)
        return nil
 }
index 0cae5ad7efcf5bb41dc1912322b29f04a34e1e11..e5c3679136c0a0a60b84963b746c632f9f26ca0b 100644 (file)
@@ -100,7 +100,8 @@ func (c *convertCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, ar
        return nil
 }
 
-func (c *convertCommand) WithCobraCommand(cmd *cobra.Command) error {
+func (c *convertCommand) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Short = "Convert your content to different formats"
        cmd.Long = `Convert your content (e.g. front matter) to different formats.
 
@@ -112,7 +113,7 @@ See convert's subcommands toJSON, toTOML and toYAML for more information.`
        return nil
 }
 
-func (c *convertCommand) Init(cd, runner *simplecobra.Commandeer) error {
+func (c *convertCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        c.r = cd.Root.Command.(*rootCommand)
        cfg := config.New()
        cfg.Set("buildDrafts", true)
index 7ff75372a141d88edc94b8fc720a1963c17aed9f..fde5ae3bcbb753c1784cac70e42a61a12d87e5bc 100644 (file)
@@ -202,12 +202,13 @@ func (c *genCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args [
        return nil
 }
 
-func (c *genCommand) WithCobraCommand(cmd *cobra.Command) error {
+func (c *genCommand) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Short = "A collection of several useful generators."
        return nil
 }
 
-func (c *genCommand) Init(cd, runner *simplecobra.Commandeer) error {
+func (c *genCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        c.rootCmd = cd.Root.Command.(*rootCommand)
        return nil
 }
index 20d23dfaccd939fd6b01294602398a5037d1cfc0..258323a3a5c4159136608b62faaebb78830648bb 100644 (file)
@@ -90,7 +90,8 @@ func (c *importCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
        return nil
 }
 
-func (c *importCommand) WithCobraCommand(cmd *cobra.Command) error {
+func (c *importCommand) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Short = "Import your site from others."
        cmd.Long = `Import your site from other web site generators like Jekyll.
 
@@ -99,7 +100,7 @@ Import requires a subcommand, e.g. ` + "`hugo import jekyll jekyll_root_path tar
        return nil
 }
 
-func (c *importCommand) Init(cd, runner *simplecobra.Commandeer) error {
+func (c *importCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        c.r = cd.Root.Command.(*rootCommand)
        return nil
 }
index 2f2e298878480d0654b8c9b63bb3faf9ea730812..1ce45987b3754e7a5803cd05329f23e865f8202a 100644 (file)
@@ -23,7 +23,6 @@ import (
        "github.com/gohugoio/hugo/hugolib"
        "github.com/gohugoio/hugo/resources/page"
        "github.com/gohugoio/hugo/resources/resource"
-       "github.com/spf13/cobra"
 )
 
 // newListCommand creates a new list command and its subcommands.
@@ -153,7 +152,8 @@ func (c *listCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
        return nil
 }
 
-func (c *listCommand) WithCobraCommand(cmd *cobra.Command) error {
+func (c *listCommand) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Short = "Listing out various types of content"
        cmd.Long = `Listing out various types of content.
 
@@ -162,6 +162,6 @@ List requires a subcommand, e.g. hugo list drafts`
        return nil
 }
 
-func (c *listCommand) Init(cd, runner *simplecobra.Commandeer) error {
+func (c *listCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        return nil
 }
index a0e488ecd1f0347bd30cf9d6583cf2824ca2a914..1af1f74314abc60d854f62e62526cdadef515814 100644 (file)
@@ -293,7 +293,8 @@ func (c *modCommands) Run(ctx context.Context, cd *simplecobra.Commandeer, args
        return nil
 }
 
-func (c *modCommands) WithCobraCommand(cmd *cobra.Command) error {
+func (c *modCommands) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Short = "Various Hugo Modules helpers."
        cmd.Long = `Various helpers to help manage the modules in your project's dependency graph.
 Most operations here requires a Go version installed on your system (>= Go 1.12) and the relevant VCS client (typically Git).
@@ -304,7 +305,7 @@ This is not needed if you only operate on modules inside /themes or if you have
        return nil
 }
 
-func (c *modCommands) Init(cd, runner *simplecobra.Commandeer) error {
+func (c *modCommands) PreRun(cd, runner *simplecobra.Commandeer) error {
        c.r = cd.Root.Command.(*rootCommand)
        return nil
 }
index 3a0e3ad71b3df756d434f19105c28c797a1d751d..5a940a1cdc70b03137dfca8b302716376d67351d 100644 (file)
@@ -271,7 +271,8 @@ func (c *newCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args [
        return nil
 }
 
-func (c *newCommand) WithCobraCommand(cmd *cobra.Command) error {
+func (c *newCommand) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Short = "Create new content for your site"
        cmd.Long = `Create a new content file and automatically set the date and title.
 It will guess which kind of file to create based on the path provided.
@@ -284,7 +285,7 @@ Ensure you run this within the root directory of your site.`
        return nil
 }
 
-func (c *newCommand) Init(cd, runner *simplecobra.Commandeer) error {
+func (c *newCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        c.rootCmd = cd.Root.Command.(*rootCommand)
        return nil
 }
index 5c2fd7704c6ff2d008a26e4a6e8e46c863184bdc..8cd7a961ffd0be0c4f3ea31b0c9800b865c62965 100644 (file)
@@ -54,7 +54,6 @@ import (
        "github.com/gohugoio/hugo/transform"
        "github.com/gohugoio/hugo/transform/livereloadinject"
        "github.com/spf13/afero"
-       "github.com/spf13/cobra"
        "github.com/spf13/fsync"
        "golang.org/x/sync/errgroup"
        "golang.org/x/sync/semaphore"
@@ -99,8 +98,7 @@ func newHugoBuilder(r *rootCommand, s *serverCommand, onConfigLoaded ...func(rel
 func newServerCommand() *serverCommand {
        var c *serverCommand
        c = &serverCommand{
-               buildFlags: &buildFlags{},
-               quit:       make(chan bool),
+               quit: make(chan bool),
        }
        return c
 }
@@ -408,10 +406,6 @@ type serverCommand struct {
        doLiveReload bool
 
        // Flags.
-
-       // Common build flags.
-       *buildFlags
-
        renderToDisk        bool
        renderStaticToDisk  bool
        navigateToChanged   bool
@@ -472,7 +466,8 @@ func (c *serverCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
        return c.serve()
 }
 
-func (c *serverCommand) WithCobraCommand(cmd *cobra.Command) error {
+func (c *serverCommand) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Short = "A high performance webserver"
        cmd.Long = `Hugo provides its own webserver which builds and serves the site.
 While hugo server is high performance, it is a webserver with limited options.
@@ -504,12 +499,13 @@ of a second, you will be able to save and see your changes nearly instantly.`
        cmd.Flags().String("memstats", "", "log memory usage to this file")
        cmd.Flags().String("meminterval", "100ms", "interval to poll memory usage (requires --memstats), valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\".")
 
-       applyLocalBuildFlags(cmd, c.buildFlags)
+       r := cd.Root.Command.(*rootCommand)
+       applyLocalBuildFlags(cmd, r)
 
        return nil
 }
 
-func (c *serverCommand) Init(cd, runner *simplecobra.Commandeer) error {
+func (c *serverCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        c.r = cd.Root.Command.(*rootCommand)
 
        c.hugoBuilder = newHugoBuilder(
index 6bb507a5e6acf2b9546117e40f16f1f8638c9423..7ceeffb19da4ca5ddad57343a3bcd360e8cc63b4 100644 (file)
@@ -66,13 +66,14 @@ func (c *templateCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, a
        return nil
 }
 
-func (c *templateCommand) WithCobraCommand(cmd *cobra.Command) error {
+func (c *templateCommand) Init(cd *simplecobra.Commandeer) error {
+       cmd := cd.CobraCommand
        cmd.Short = "Print the site configuration"
        cmd.Long = `Print the site configuration, both default and custom settings.`
        return nil
 }
 
-func (c *templateCommand) Init(cd, runner *simplecobra.Commandeer) error {
+func (c *templateCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        c.r = cd.Root.Command.(*rootCommand)
        return nil
 }
index a519147725330d2f18a98829a53dff30a5be8605..c09962f6379dde2893cb4d6e596c3c14dd656ae1 100644 (file)
@@ -23,6 +23,7 @@ import (
        "sort"
        "strconv"
        "strings"
+       "sync"
        "time"
 
        "github.com/gohugoio/hugo/cache/filecache"
@@ -92,7 +93,7 @@ type Config struct {
        // For internal use only.
        Internal InternalConfig `mapstructure:"-" json:"-"`
        // For internal use only.
-       C ConfigCompiled `mapstructure:"-" json:"-"`
+       C *ConfigCompiled `mapstructure:"-" json:"-"`
 
        RootConfig
 
@@ -188,6 +189,8 @@ type configCompiler interface {
 
 func (c Config) cloneForLang() *Config {
        x := c
+       x.C = nil
+
        // Collapse all static dirs to one.
        x.StaticDir = x.staticDirs()
        // These will go away soon ...
@@ -302,7 +305,7 @@ func (c *Config) CompileConfig() error {
                }
        }
 
-       c.C = ConfigCompiled{
+       c.C = &ConfigCompiled{
                Timeout:           timeout,
                BaseURL:           baseURL,
                BaseURLLiveReload: baseURL,
@@ -329,11 +332,11 @@ func (c *Config) CompileConfig() error {
        return nil
 }
 
-func (c Config) IsKindEnabled(kind string) bool {
+func (c *Config) IsKindEnabled(kind string) bool {
        return !c.C.DisabledKinds[kind]
 }
 
-func (c Config) IsLangDisabled(lang string) bool {
+func (c *Config) IsLangDisabled(lang string) bool {
        return c.C.DisabledLanguages[lang]
 }
 
@@ -356,10 +359,17 @@ type ConfigCompiled struct {
        // With themes/modules we compute the configuration in multiple passes, and
        // errors with missing output format definitions may resolve itself.
        transientErr error
+
+       mu sync.Mutex
 }
 
 // This may be set after the config is compiled.
-func (c *ConfigCompiled) SetMainSections(sections []string) {
+func (c *ConfigCompiled) SetMainSectionsIfNotSet(sections []string) {
+       c.mu.Lock()
+       defer c.mu.Unlock()
+       if len(c.MainSections) > 0 {
+               return
+       }
        c.MainSections = sections
 }
 
diff --git a/go.mod b/go.mod
index 171d3921f1b419cc853f3f268627e9f89a83aea5..d494ee7eb391943b5d402f206e6a759780ce4717 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -95,7 +95,7 @@ require (
        github.com/aws/aws-sdk-go-v2/service/sts v1.7.0 // indirect
        github.com/aws/smithy-go v1.8.0 // indirect
        github.com/bep/helpers v0.4.0 // indirect
-       github.com/bep/simplecobra v0.2.0 // indirect
+       github.com/bep/simplecobra v0.3.0 // indirect
        github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
        github.com/dlclark/regexp2 v1.7.0 // indirect
        github.com/go-openapi/jsonpointer v0.19.5 // indirect
diff --git a/go.sum b/go.sum
index 30af63f39e304ca83b4219b3c6bcd786ff429ae5..50f1ea6a77a257bafa36251482b3a1bb3ca846a6 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -187,6 +187,8 @@ github.com/bep/overlayfs v0.6.0 h1:sgLcq/qtIzbaQNl2TldGXOkHvqeZB025sPvHOQL+DYo=
 github.com/bep/overlayfs v0.6.0/go.mod h1:NFjSmn3kCqG7KX2Lmz8qT8VhPPCwZap3UNogXawoQHM=
 github.com/bep/simplecobra v0.2.0 h1:gfdZZ8QlPBMC9R9DRzUsxExR3FyuNtRkqMJqK98SBno=
 github.com/bep/simplecobra v0.2.0/go.mod h1:EOp6bCKuuHmwA9bQcRC8LcDB60co2Cmht5X4xMIOwf0=
+github.com/bep/simplecobra v0.3.0 h1:BEeb/Q5qdsv5Yy9Go30ynZtAbI+jHV4f5VtNSXvp91E=
+github.com/bep/simplecobra v0.3.0/go.mod h1:EOp6bCKuuHmwA9bQcRC8LcDB60co2Cmht5X4xMIOwf0=
 github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI=
 github.com/bep/tmc v0.5.1/go.mod h1:tGYHN8fS85aJPhDLgXETVKp+PR382OvFi2+q2GkGsq0=
 github.com/bep/workers v1.0.0 h1:U+H8YmEaBCEaFZBst7GcRVEoqeRC9dzH2dWOwGmOchg=
index 1b6fd40e9e07aede110f9c2ef146bed225c63b7e..6f02e2e2956d9a0d07fb4aceb60ee50dd4385747 100644 (file)
@@ -743,9 +743,12 @@ func (m *pageMaps) AssemblePages() error {
                sw := &sectionWalker{m: pm.contentMap}
                a := sw.applyAggregates()
 
-               if a.mainSection != "" && len(pm.s.s.conf.C.MainSections) == 0 {
+               if a.mainSection != "" {
+                       // Note, sites that have no custom config share a common config struct pointer.
+                       // This means that we currently do not support setting different values per language.
+                       // The end user can, however, configure this per language if needed.
                        mainSections := []string{strings.TrimRight(a.mainSection, "/")}
-                       pm.s.s.conf.C.SetMainSections(mainSections)
+                       pm.s.s.conf.C.SetMainSectionsIfNotSet(mainSections)
                }
                pm.s.lastmod = a.datesAll.Lastmod()
                if resource.IsZeroDates(pm.s.home) {
diff --git a/testscripts/commands/server.txt b/testscripts/commands/server.txt
new file mode 100644 (file)
index 0000000..fd6b200
--- /dev/null
@@ -0,0 +1,30 @@
+# Test the hugo server command.
+
+# We run these tests in parallel so let Hugo decide which port to use.
+hugo server --gc &
+
+waitServer
+
+httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0 'ServerPort: \d{4,5}' 'myenv: thedevelopment' 'livereload\.js' 'Env: development' 'IsServer: true'
+httpget ${HUGOTEST_BASEURL_0}doesnotexist 'custom 404'
+
+# By defauilt, the server renders to memory.
+! exists public/index.html
+
+stopServer
+! stderr .
+
+-- hugo.toml --
+title = "Hugo Server Test"
+baseURL = "https://example.org/"
+disableKinds = ["taxonomy", "term", "sitemap"]
+-- config/production/params.toml --
+myenv = "theproduction"
+-- config/development/params.toml --
+myenv = "thedevelopment"
+-- layouts/index.html --
+<body>
+Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}|ServerPort: {{ site.ServerPort }}|myenv: {{ .Site.Params.myenv }}|Env: {{ hugo.Environment }}|IsServer: {{ site.IsServer }}|
+</body>
+-- layouts/404.html --
+custom 404
diff --git a/testscripts/unfinished/server.txt b/testscripts/unfinished/server.txt
deleted file mode 100644 (file)
index fd6b200..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-# Test the hugo server command.
-
-# We run these tests in parallel so let Hugo decide which port to use.
-hugo server --gc &
-
-waitServer
-
-httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0 'ServerPort: \d{4,5}' 'myenv: thedevelopment' 'livereload\.js' 'Env: development' 'IsServer: true'
-httpget ${HUGOTEST_BASEURL_0}doesnotexist 'custom 404'
-
-# By defauilt, the server renders to memory.
-! exists public/index.html
-
-stopServer
-! stderr .
-
--- hugo.toml --
-title = "Hugo Server Test"
-baseURL = "https://example.org/"
-disableKinds = ["taxonomy", "term", "sitemap"]
--- config/production/params.toml --
-myenv = "theproduction"
--- config/development/params.toml --
-myenv = "thedevelopment"
--- layouts/index.html --
-<body>
-Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}|ServerPort: {{ site.ServerPort }}|myenv: {{ .Site.Params.myenv }}|Env: {{ hugo.Environment }}|IsServer: {{ site.IsServer }}|
-</body>
--- layouts/404.html --
-custom 404