summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2021-08-31 13:27:13 +0200
committerMartin Polden <mpolden@mpolden.no>2021-08-31 14:01:34 +0200
commita17eed4a8a43510b170657436b2e4df8a59597fd (patch)
treecdf8578f953b0ba5725e7206385833346f3537fb /client
parentc870d79b4903bd5bef1bf062b797239c8893cf17 (diff)
Fix incorrect config binding
Diffstat (limited to 'client')
-rw-r--r--client/go/cmd/config.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/client/go/cmd/config.go b/client/go/cmd/config.go
index 87619deb3a5..3b28a51d544 100644
--- a/client/go/cmd/config.go
+++ b/client/go/cmd/config.go
@@ -21,10 +21,13 @@ const (
configType = "yaml"
)
+var flagToConfigBindings map[string][]*cobra.Command
+
func init() {
rootCmd.AddCommand(configCmd)
configCmd.AddCommand(setConfigCmd)
configCmd.AddCommand(getConfigCmd)
+ flagToConfigBindings = make(map[string][]*cobra.Command)
}
var configCmd = &cobra.Command{
@@ -81,24 +84,33 @@ func configDir(application string) (string, error) {
}
func bindFlagToConfig(option string, command *cobra.Command) {
- viper.BindPFlag(option, command.PersistentFlags().Lookup(option))
+ flagToConfigBindings[option] = append(flagToConfigBindings[option], command)
}
func readConfig() {
configDir, err := configDir("")
- cobra.CheckErr(err)
-
+ if err != nil {
+ log.Print(color.Red("Error:"), "Could not determine configuration directory")
+ log.Print(color.Brown(err))
+ return
+ }
viper.SetConfigName(configName)
viper.SetConfigType(configType)
viper.AddConfigPath(configDir)
viper.AutomaticEnv()
- viper.BindPFlag("target", deployCmd.PersistentFlags().Lookup("target"))
-
+ for option, commands := range flagToConfigBindings {
+ for _, command := range commands {
+ viper.BindPFlag(option, command.PersistentFlags().Lookup(option))
+ }
+ }
err = viper.ReadInConfig()
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
return // Fine
}
- cobra.CheckErr(err)
+ if err != nil {
+ log.Print(color.Red("Error:"), "Could read configuration")
+ log.Print(color.Brown(err))
+ }
}
func getOption(option string) (string, error) {