summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Harniakou <anton.harniakou@gmail.com>2019-01-31 15:06:18 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-02-01 07:17:37 +0100
commitd9282cf98a346fcf98f363d9c353e4920ca85fc7 (patch)
tree440d1c8d3d5fc49f93c2df814003b75e84965ad6
parentc52045bbb38cbf64b9cb39352230060aa122cc9f (diff)
Store supported config formats in a variable
-rw-r--r--commands/commands.go3
-rw-r--r--config/configLoader.go4
-rw-r--r--hugolib/config.go2
-rw-r--r--hugolib/paths/themes.go2
4 files changed, 7 insertions, 4 deletions
diff --git a/commands/commands.go b/commands/commands.go
index c2fb90830..38291fd95 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -167,8 +167,7 @@ Complete documentation is available at http://gohugo.io/.`,
cc.cmd.PersistentFlags().BoolVar(&cc.quiet, "quiet", false, "build in quiet mode")
// Set bash-completion
- validConfigFilenames := []string{"json", "js", "yaml", "yml", "toml", "tml"}
- _ = cc.cmd.PersistentFlags().SetAnnotation("config", cobra.BashCompFilenameExt, validConfigFilenames)
+ _ = cc.cmd.PersistentFlags().SetAnnotation("config", cobra.BashCompFilenameExt, config.ValidConfigFileExtensions)
cc.cmd.PersistentFlags().BoolVarP(&cc.verbose, "verbose", "v", false, "verbose output")
cc.cmd.PersistentFlags().BoolVarP(&cc.debug, "debug", "", false, "debug output")
diff --git a/config/configLoader.go b/config/configLoader.go
index 31e3e00e4..f2265dc6a 100644
--- a/config/configLoader.go
+++ b/config/configLoader.go
@@ -20,6 +20,10 @@ import (
"github.com/spf13/viper"
)
+var (
+ ValidConfigFileExtensions = []string{"toml", "yaml", "yml", "json"}
+)
+
// FromConfigString creates a config from the given YAML, JSON or TOML config. This is useful in tests.
func FromConfigString(config, configType string) (Provider, error) {
v := newViper()
diff --git a/hugolib/config.go b/hugolib/config.go
index 504043d79..5b56333df 100644
--- a/hugolib/config.go
+++ b/hugolib/config.go
@@ -202,7 +202,7 @@ func (l configLoader) loadConfig(configName string, v *viper.Viper) (string, err
filename = baseFilename
}
} else {
- for _, ext := range []string{"toml", "yaml", "yml", "json"} {
+ for _, ext := range config.ValidConfigFileExtensions {
filenameToCheck := baseFilename + "." + ext
exists, _ := helpers.Exists(filenameToCheck, l.Fs)
if exists {
diff --git a/hugolib/paths/themes.go b/hugolib/paths/themes.go
index 1ce8e7997..4718720e1 100644
--- a/hugolib/paths/themes.go
+++ b/hugolib/paths/themes.go
@@ -120,7 +120,7 @@ func (c *themesCollector) getConfigFileIfProvided(theme string) string {
)
// Viper supports more, but this is the sub-set supported by Hugo.
- for _, configFormats := range []string{"toml", "yaml", "yml", "json"} {
+ for _, configFormats := range config.ValidConfigFileExtensions {
configFilename = filepath.Join(configDir, "config."+configFormats)
exists, _ = afero.Exists(c.fs, configFilename)
if exists {