Skip to content

Commit

Permalink
Get values from ENV first
Browse files Browse the repository at this point in the history
  • Loading branch information
kwent committed Feb 10, 2024
1 parent b37dd24 commit 520984d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pkg/inputs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 520984d

Please sign in to comment.