Commit cae0ce5c authored by Sietse Ringers's avatar Sietse Ringers
Browse files

refactor: reuse already defined dashReplacer in viper config normalization function

parent 5d6da77e
......@@ -87,13 +87,11 @@ func readConfig(cmd *cobra.Command, name, logname string, configpaths []string,
viper.SetEnvPrefix(strings.ToUpper(name))
viper.AutomaticEnv()
// bind cmd flags to viper, replacing dashes with underscores
// Bind cmd flags to viper, such that configuration files use underscores instead of dashes
f := cmd.Flags()
normalizeFunc := f.GetNormalizeFunc()
f.SetNormalizeFunc(func(fs *pflag.FlagSet, name string) pflag.NormalizedName {
result := normalizeFunc(fs, name)
name = strings.ReplaceAll(string(result), "-", "_")
return pflag.NormalizedName(name)
return pflag.NormalizedName(dashReplacer.Replace(string(normalizeFunc(fs, name))))
})
if err := viper.BindPFlags(f); err != nil {
die("", err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment