Store supported config formats in a variable
authorAnton Harniakou <anton.harniakou@gmail.com>
Thu, 31 Jan 2019 12:06:18 +0000 (15:06 +0300)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 1 Feb 2019 06:17:37 +0000 (07:17 +0100)
commands/commands.go
config/configLoader.go
hugolib/config.go
hugolib/paths/themes.go

index c2fb90830f2ebd7b62ae8f65713c79834a372e81..38291fd958a6791007bdea2fa64a76b0e3b1ecb6 100644 (file)
@@ -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")
index 31e3e00e42602803f01ff16e1b6c6c5182100b0b..f2265dc6a88d39f90a4574dd158114e176a1e86c 100644 (file)
@@ -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()
index 504043d79211e35b1bab87a7de90a4dbb9532b74..5b56333df852105c80162472d7a2e620d293686d 100644 (file)
@@ -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 {
index 1ce8e7997a693a18201d277769db628aea5597fd..4718720e1d0b6d4b9c01895bbfbc481b4675378a 100644 (file)
@@ -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 {