From 2af4ed93736582cb5cfe94fc802f93c0f6f3b466 Mon Sep 17 00:00:00 2001 From: 1138-4EB <1138-4EB@users.noreply.github.com> Date: Tue, 8 Jan 2019 20:49:27 +0100 Subject: [PATCH] style: move --- cmd/root.go | 58 ++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 9a652be0..b86af4fc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -131,35 +131,6 @@ user created with the credentials from options "username" and "password".`, }, pythonConfig{allowNoDB: true}), } -// getParamB returns a parameter as a string and a boolean to tell if it is different from the default -// -// NOTE: we could simply bind the flags to viper and use IsSet. -// Although there is a bug on Viper that always returns true on IsSet -// if a flag is binded. Our alternative way is to manually check -// the flag and then the value from env/config/gotten by viper. -// https://github.com/spf13/viper/pull/331 -func getParamB(flags *pflag.FlagSet, key string) (string, bool) { - value, _ := flags.GetString(key) - - // If set on Flags, use it. - if flags.Changed(key) { - return value, true - } - - // If set through viper (env, config), return it. - if v.IsSet(key) { - return v.GetString(key), true - } - - // Otherwise use default value on flags. - return value, false -} - -func getParam(flags *pflag.FlagSet, key string) string { - val, _ := getParamB(flags, key) - return val -} - func getServerWithViper(flags *pflag.FlagSet, st *storage.Storage) *settings.Server { server, err := st.Settings.GetServer() checkErr(err) @@ -195,6 +166,35 @@ func getServerWithViper(flags *pflag.FlagSet, st *storage.Storage) *settings.Ser return server } +// getParamB returns a parameter as a string and a boolean to tell if it is different from the default +// +// NOTE: we could simply bind the flags to viper and use IsSet. +// Although there is a bug on Viper that always returns true on IsSet +// if a flag is binded. Our alternative way is to manually check +// the flag and then the value from env/config/gotten by viper. +// https://github.com/spf13/viper/pull/331 +func getParamB(flags *pflag.FlagSet, key string) (string, bool) { + value, _ := flags.GetString(key) + + // If set on Flags, use it. + if flags.Changed(key) { + return value, true + } + + // If set through viper (env, config), return it. + if v.IsSet(key) { + return v.GetString(key), true + } + + // Otherwise use default value on flags. + return value, false +} + +func getParam(flags *pflag.FlagSet, key string) string { + val, _ := getParamB(flags, key) + return val +} + func setupLog(logMethod string) { switch logMethod { case "stdout":