mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Store supported config formats in a variable
This commit is contained in:
parent
c52045bbb3
commit
d9282cf98a
4 changed files with 7 additions and 4 deletions
|
@ -167,8 +167,7 @@ Complete documentation is available at http://gohugo.io/.`,
|
||||||
cc.cmd.PersistentFlags().BoolVar(&cc.quiet, "quiet", false, "build in quiet mode")
|
cc.cmd.PersistentFlags().BoolVar(&cc.quiet, "quiet", false, "build in quiet mode")
|
||||||
|
|
||||||
// Set bash-completion
|
// Set bash-completion
|
||||||
validConfigFilenames := []string{"json", "js", "yaml", "yml", "toml", "tml"}
|
_ = cc.cmd.PersistentFlags().SetAnnotation("config", cobra.BashCompFilenameExt, config.ValidConfigFileExtensions)
|
||||||
_ = cc.cmd.PersistentFlags().SetAnnotation("config", cobra.BashCompFilenameExt, validConfigFilenames)
|
|
||||||
|
|
||||||
cc.cmd.PersistentFlags().BoolVarP(&cc.verbose, "verbose", "v", false, "verbose output")
|
cc.cmd.PersistentFlags().BoolVarP(&cc.verbose, "verbose", "v", false, "verbose output")
|
||||||
cc.cmd.PersistentFlags().BoolVarP(&cc.debug, "debug", "", false, "debug output")
|
cc.cmd.PersistentFlags().BoolVarP(&cc.debug, "debug", "", false, "debug output")
|
||||||
|
|
|
@ -20,6 +20,10 @@ import (
|
||||||
"github.com/spf13/viper"
|
"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.
|
// FromConfigString creates a config from the given YAML, JSON or TOML config. This is useful in tests.
|
||||||
func FromConfigString(config, configType string) (Provider, error) {
|
func FromConfigString(config, configType string) (Provider, error) {
|
||||||
v := newViper()
|
v := newViper()
|
||||||
|
|
|
@ -202,7 +202,7 @@ func (l configLoader) loadConfig(configName string, v *viper.Viper) (string, err
|
||||||
filename = baseFilename
|
filename = baseFilename
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, ext := range []string{"toml", "yaml", "yml", "json"} {
|
for _, ext := range config.ValidConfigFileExtensions {
|
||||||
filenameToCheck := baseFilename + "." + ext
|
filenameToCheck := baseFilename + "." + ext
|
||||||
exists, _ := helpers.Exists(filenameToCheck, l.Fs)
|
exists, _ := helpers.Exists(filenameToCheck, l.Fs)
|
||||||
if exists {
|
if exists {
|
||||||
|
|
|
@ -120,7 +120,7 @@ func (c *themesCollector) getConfigFileIfProvided(theme string) string {
|
||||||
)
|
)
|
||||||
|
|
||||||
// Viper supports more, but this is the sub-set supported by Hugo.
|
// 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)
|
configFilename = filepath.Join(configDir, "config."+configFormats)
|
||||||
exists, _ = afero.Exists(c.fs, configFilename)
|
exists, _ = afero.Exists(c.fs, configFilename)
|
||||||
if exists {
|
if exists {
|
||||||
|
|
Loading…
Reference in a new issue