Skip to content

Commit

Permalink
Updates initConfigFile to be more permissive of YAML structures
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowiem committed Jun 20, 2020
1 parent 4800565 commit 744a63c
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,32 @@ func initConfigFile() error {
return err
}

config := make(map[string]map[string]interface{})
config := make(map[string]interface{})
if err := yaml.Unmarshal(file, &config); err != nil {
return err
}

log.Debug("Full config file contents: ", config)

// Ooof this is rough.
configEntry := viper.GetString("config")
rawEntry := config[configEntry].(map[interface{}]interface{})
entry := make(map[string]interface{})
for key, val := range rawEntry {
strKey := fmt.Sprintf("%v", key)
var resVal interface{}

if strKey == "cmd" {
resVal = val.([]interface{})
} else {
resVal = fmt.Sprintf("%v", val)
}

entry[strKey] = resVal
}

log.Debug("Config entry: ", configEntry, " result: ", config[configEntry])
if err = viper.MergeConfigMap(config[configEntry]); err != nil {
log.Debug("Config entry: ", configEntry, " result: ", entry)
if err = viper.MergeConfigMap(entry); err != nil {
return err
}

Expand Down

0 comments on commit 744a63c

Please sign in to comment.