Repository: gohugoio/hugo (language: go)

Issue:
Add --lang to hugo config
Currently it displays the "first language"'s config (which should still be the default), but we need a way to print the others (even if lots of the config are common and language agnostic).


Discussion / hints:

Fix patch:
diff --git a/commands/config.go b/commands/config.go
index 44c5a1c32eb..fe20196aace 100644
--- a/commands/config.go
+++ b/commands/config.go
@@ -23,6 +23,7 @@ import (
 	"time"
 
 	"github.com/bep/simplecobra"
+	"github.com/gohugoio/hugo/config/allconfig"
 	"github.com/gohugoio/hugo/modules"
 	"github.com/gohugoio/hugo/parser"
 	"github.com/gohugoio/hugo/parser/metadecoders"
@@ -42,6 +43,7 @@ type configCommand struct {
 	r *rootCommand
 
 	format string
+	lang   string
 
 	commands []simplecobra.Commander
 }
@@ -59,7 +61,16 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
 	if err != nil {
 		return err
 	}
-	config := conf.configs.Base
+	var config *allconfig.Config
+	if c.lang != "" {
+		var found bool
+		config, found = conf.configs.LanguageConfigMap[c.lang]
+		if !found {
+			return fmt.Errorf("language %q not found", c.lang)
+		}
+	} else {
+		config = conf.configs.LanguageConfigSlice[0]
+	}
 
 	var buf bytes.Buffer
 	dec := json.NewEncoder(&buf)
@@ -100,6 +111,7 @@ func (c *configCommand) Init(cd *simplecobra.Commandeer) error {
 	cmd.Short = "Print the site configuration"
 	cmd.Long = `Print the site configuration, both default and custom settings.`
 	cmd.Flags().StringVar(&c.format, "format", "toml", "preferred file format (toml, yaml or json)")
+	cmd.Flags().StringVar(&c.lang, "lang", "", "the language to display config for. Defaults to the first language defined.")
 	applyLocalFlagsBuildConfig(cmd, c.r)
 
 	return nil
diff --git a/config/allconfig/allconfig.go b/config/allconfig/allconfig.go
index abb95554658..ade9607dded 100644
--- a/config/allconfig/allconfig.go
+++ b/config/allconfig/allconfig.go
@@ -649,6 +649,26 @@ func (c *Configs) Init() error {
 		return err
 	}
 
+	// We should consolidate this, but to get a full view of the mounts in e.g. "hugo config" we need to
+	// transfer any default mounts added above to the config used to print the config.
+	for _, m := range c.Modules[0].Mounts() {
+		var found bool
+		for _, cm := range c.Base.Module.Mounts {
+			if cm.Source == m.Source && cm.Target == m.Target && cm.Lang == m.Lang {
+				found = true
+				break
+			}
+		}
+		if !found {
+			c.Base.Module.Mounts = append(c.Base.Module.Mounts, m)
+		}
+	}
+
+	// Transfer the changed mounts to the language versions (all share the same mount set, but can be displayed in different languages).
+	for _, l := range c.LanguageConfigSlice {
+		l.Module.Mounts = c.Base.Module.Mounts
+	}
+
 	return nil
 }
 


Test patch:
diff --git a/config/allconfig/integration_test.go b/config/allconfig/integration_test.go
index e96dbd29689..2de83eaa4cc 100644
--- a/config/allconfig/integration_test.go
+++ b/config/allconfig/integration_test.go
@@ -60,7 +60,7 @@ Title: {{ .Title }}
 
 	b.Assert(enConcp.BaseURL().String(), qt.Equals, "https://example.com")
 	modConf := enConf.Module
-	b.Assert(modConf.Mounts, qt.HasLen, 2)
+	b.Assert(modConf.Mounts, qt.HasLen, 8)
 	b.Assert(modConf.Mounts[0].Source, qt.Equals, filepath.FromSlash("content/en"))
 	b.Assert(modConf.Mounts[0].Target, qt.Equals, "content")
 	b.Assert(modConf.Mounts[0].Lang, qt.Equals, "en")
diff --git a/hugolib/config_test.go b/hugolib/config_test.go
index 814be667f06..3b137d8d673 100644
--- a/hugolib/config_test.go
+++ b/hugolib/config_test.go
@@ -1151,3 +1151,28 @@ weight = 1
 	})
 
 }
+
+// Issue #11040
+func TestConfigModuleDefaultMountsInConfig(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+baseURL = "https://example.org"
+contentDir = "mycontent"
+-- layouts/index.html --
+Home.
+
+	
+`
+	b := NewIntegrationTestBuilder(
+		IntegrationTestConfig{
+			T:           t,
+			TxtarString: files,
+		},
+	).Build()
+
+	b.Assert(b.H.Configs.Base.Module.Mounts, qt.HasLen, 7)
+	b.Assert(b.H.Configs.LanguageConfigSlice[0].Module.Mounts, qt.HasLen, 7)
+
+}