Fix handling of --contentDir etc. flag

We need to revisit the commands package re globals and tests, but this should fix the init order of flags and languages.

Fixes #4589
This commit is contained in:
Bjørn Erik Pedersen
2018-04-07 11:27:22 +02:00
parent 094ec17142
commit 080302eb87
4 changed files with 89 additions and 56 deletions

View File

@@ -54,7 +54,7 @@ func LoadConfigDefault(fs afero.Fs) (*viper.Viper, error) {
// LoadConfig loads Hugo configuration into a new Viper and then adds
// a set of defaults.
func LoadConfig(d ConfigSourceDescriptor) (*viper.Viper, []string, error) {
func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provider) error) (*viper.Viper, []string, error) {
var configFiles []string
fs := d.Fs
@@ -108,6 +108,14 @@ func LoadConfig(d ConfigSourceDescriptor) (*viper.Viper, []string, error) {
configFiles = append(configFiles, themeConfigFile)
}
// We create languages based on the settings, so we need to make sure that
// all configuration is loaded/set before doing that.
for _, d := range doWithConfig {
if err := d(v); err != nil {
return v, configFiles, err
}
}
if err := loadLanguageSettings(v, nil); err != nil {
return v, configFiles, err
}