From 520984dbb3024b3d9ba12f3e2b951d18694639ef Mon Sep 17 00:00:00 2001 From: Quentin Rousseau Date: Fri, 9 Feb 2024 19:48:08 -0800 Subject: [PATCH] Get values from ENV first --- pkg/inputs/get.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pkg/inputs/get.go b/pkg/inputs/get.go index 8dac5d7..2e3acd8 100644 --- a/pkg/inputs/get.go +++ b/pkg/inputs/get.go @@ -16,17 +16,22 @@ func errIfNoVal(name models.ConfigPiece) log.CtxErr { // Get a string configuration value func GetString(name models.ConfigPiece, cmd *cobra.Command, required bool) (string, log.CtxErr) { - // Getting the value from a command line flag if possible - val, err := flags.GetString(name, cmd) - if err.Error != nil { - return "", err - } - if val != "" { - return val, err + + // Getting value from env first + err := log.CtxErr{} + val := env.GetString(name) + + if val == "" { + // Getting the value from a command line flag if possible + val, err = flags.GetString(name, cmd) + if err.Error != nil { + return "", err + } + if val != "" { + return val, err + } } - // No value from flag so falling back on possible env var - val = env.GetString(name) if val == "" && required { return "", errIfNoVal(name) }