Skip to content

Commit

Permalink
improved error handling 2 func bindEnvToFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
y-eight committed Nov 16, 2022
1 parent 06ffe4f commit af60594
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ func bindEnvToFlags(cmd *cobra.Command, v *viper.Viper) {
// Apply the viper config value to the flag when the flag is not set and viper has a value
if !f.Changed && v.IsSet(f.Name) {
val := v.GetString(f.Name)
cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val))
err := cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val))
if err != nil {
log.Printf("Could not apply viper config to flag: %v", v.GetString(f.Name))
}
}
})
}

0 comments on commit af60594

Please sign in to comment.