diff options
author | Bjørn Erik Pedersen <[email protected]> | 2021-06-09 10:58:18 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-06-14 17:00:32 +0200 |
commit | d392893cd73dc00c927f342778f6dca9628d328e (patch) | |
tree | e2ea3eec09f36b7122ecdbc498c3c130e240e85c /commands | |
parent | a886dd53b80322e1edf924f2ede4d4ea037c5baf (diff) | |
download | hugo-d392893cd73dc00c927f342778f6dca9628d328e.tar.gz hugo-d392893cd73dc00c927f342778f6dca9628d328e.zip |
Misc config loading fixes
The main motivation behind this is simplicity and correctnes, but the new small config library is also faster:
```
BenchmarkDefaultConfigProvider/Viper-16 252418 4546 ns/op 2720 B/op 30 allocs/op
BenchmarkDefaultConfigProvider/Custom-16 450756 2651 ns/op 1008 B/op 6 allocs/op
```
Fixes #8633
Fixes #8618
Fixes #8630
Updates #8591
Closes #6680
Closes #5192
Diffstat (limited to 'commands')
-rw-r--r-- | commands/commandeer.go | 2 | ||||
-rw-r--r-- | commands/commands_test.go | 9 | ||||
-rw-r--r-- | commands/config.go | 5 | ||||
-rw-r--r-- | commands/new_site.go | 4 | ||||
-rw-r--r-- | commands/server_test.go | 4 |
5 files changed, 12 insertions, 12 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go index 024651aad..06e27cf18 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -410,7 +410,5 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { } config.Set("cacheDir", cacheDir) - cfg.Logger.Infoln("Using config file:", config.ConfigFileUsed()) - return nil } diff --git a/commands/commands_test.go b/commands/commands_test.go index a0eeb157b..99ffea48c 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -20,6 +20,8 @@ import ( "path/filepath" "testing" + "github.com/gohugoio/hugo/config" + "github.com/gohugoio/hugo/htesting" "github.com/spf13/afero" @@ -29,7 +31,6 @@ import ( "github.com/gohugoio/hugo/common/types" "github.com/spf13/cobra" - "github.com/spf13/viper" qt "github.com/frankban/quicktest" ) @@ -166,7 +167,7 @@ func TestFlags(t *testing.T) { name: "ignoreVendor as bool", args: []string{"server", "--ignoreVendor"}, check: func(c *qt.C, cmd *serverCmd) { - cfg := viper.New() + cfg := config.New() cmd.flagsToConfig(cfg) c.Assert(cfg.Get("ignoreVendor"), qt.Equals, true) }, @@ -176,7 +177,7 @@ func TestFlags(t *testing.T) { name: "ignoreVendorPaths", args: []string{"server", "--ignoreVendorPaths=github.com/**"}, check: func(c *qt.C, cmd *serverCmd) { - cfg := viper.New() + cfg := config.New() cmd.flagsToConfig(cfg) c.Assert(cfg.Get("ignoreVendorPaths"), qt.Equals, "github.com/**") }, @@ -216,7 +217,7 @@ func TestFlags(t *testing.T) { c.Assert(sc.serverPort, qt.Equals, 1366) c.Assert(sc.environment, qt.Equals, "testing") - cfg := viper.New() + cfg := config.New() sc.flagsToConfig(cfg) c.Assert(cfg.GetString("publishDir"), qt.Equals, "/tmp/mydestination") c.Assert(cfg.GetString("contentDir"), qt.Equals, "mycontent") diff --git a/commands/config.go b/commands/config.go index 37bf45e3c..7ab429308 100644 --- a/commands/config.go +++ b/commands/config.go @@ -22,13 +22,14 @@ import ( "sort" "strings" + "github.com/gohugoio/hugo/common/maps" + "github.com/gohugoio/hugo/parser" "github.com/gohugoio/hugo/parser/metadecoders" "github.com/gohugoio/hugo/modules" "github.com/spf13/cobra" - "github.com/spf13/viper" ) var _ cmder = (*configCmd)(nil) @@ -81,7 +82,7 @@ func (c *configCmd) printConfig(cmd *cobra.Command, args []string) error { return err } - allSettings := cfg.Cfg.(*viper.Viper).AllSettings() + allSettings := cfg.Cfg.Get("").(maps.Params) // We need to clean up this, but we store objects in the config that // isn't really interesting to the end user, so filter these. diff --git a/commands/new_site.go b/commands/new_site.go index 6fac2c22c..71097b8ff 100644 --- a/commands/new_site.go +++ b/commands/new_site.go @@ -19,6 +19,7 @@ import ( "path/filepath" "strings" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/parser/metadecoders" _errors "github.com/pkg/errors" @@ -29,7 +30,6 @@ import ( "github.com/gohugoio/hugo/parser" "github.com/spf13/cobra" jww "github.com/spf13/jwalterweatherman" - "github.com/spf13/viper" ) var _ cmder = (*newSiteCmd)(nil) @@ -123,7 +123,7 @@ func (n *newSiteCmd) newSite(cmd *cobra.Command, args []string) error { forceNew, _ := cmd.Flags().GetBool("force") - return n.doNewSite(hugofs.NewDefault(viper.New()), createpath, forceNew) + return n.doNewSite(hugofs.NewDefault(config.New()), createpath, forceNew) } func createConfig(fs *hugofs.Fs, inpath string, kind string) (err error) { diff --git a/commands/server_test.go b/commands/server_test.go index cc2a6d92c..05d21a516 100644 --- a/commands/server_test.go +++ b/commands/server_test.go @@ -22,10 +22,10 @@ import ( "testing" "time" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/helpers" qt "github.com/frankban/quicktest" - "github.com/spf13/viper" ) func TestServer(t *testing.T) { @@ -101,7 +101,7 @@ func TestFixURL(t *testing.T) { t.Run(test.TestName, func(t *testing.T) { b := newCommandsBuilder() s := b.newServerCmd() - v := viper.New() + v := config.New() baseURL := test.CLIBaseURL v.Set("baseURL", test.CfgBaseURL) s.serverAppend = test.AppendPort |