Fixed issue with overriding default config values via command line

This commit is contained in:
Torkel Ödegaard
2015-04-10 10:58:32 +02:00
parent 4c6d7630cd
commit 2020fedfdb
10 changed files with 257 additions and 57 deletions
+28 -6
View File
@@ -225,6 +225,33 @@ func evalConfigValues() {
}
}
func loadSpecifedConfigFile(configFile string) {
userConfig, err := ini.Load(configFile)
if err != nil {
log.Fatal(3, "Failed to parse %v, %v", configFile, err)
}
for _, section := range userConfig.Sections() {
for _, key := range section.Keys() {
if key.Value() == "" {
continue
}
defaultSec, err := Cfg.GetSection(section.Name())
if err != nil {
log.Fatal(3, "Unknown config section %s defined in %s", section.Name(), configFile)
}
defaultKey, err := defaultSec.GetKey(key.Name())
if err != nil {
log.Fatal(3, "Unknown config key %s defined in section %s, in file", key.Name(), section.Name(), configFile)
}
defaultKey.SetValue(key.Value())
}
}
configFiles = append(configFiles, configFile)
}
func loadConfiguration(args *CommandLineArgs) {
var err error
@@ -249,12 +276,7 @@ func loadConfiguration(args *CommandLineArgs) {
// load specified config file
if args.Config != "" {
err = Cfg.Append(args.Config)
if err != nil {
log.Fatal(3, "Failed to parse %v, %v", args.Config, err)
}
configFiles = append(configFiles, args.Config)
appliedCommandLineProperties = append(appliedCommandLineProperties, "config="+args.Config)
loadSpecifedConfigFile(args.Config)
}
// apply environment overrides