Skip to content

Commit

Permalink
Changing env.Getenv behavior
Browse files Browse the repository at this point in the history
Changes the env.Getenv behavior to properly follow usql/bash style
behavior. Now short circuits/stops on the first encountered environment
variable of the set of provided keys. This fixes an issue where
explicitly defining an environment variable does not effectively disable
that value, eg, USQL_PAGER and others.
  • Loading branch information
kenshaw committed Sep 12, 2022
1 parent f4de584 commit 61222d3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ import (

// Getenv tries retrieving successive keys from os environment variables.
func Getenv(keys ...string) string {
m := make(map[string]string)
for _, v := range os.Environ() {
if i := strings.Index(v, "="); i != -1 {
m[v[:i]] = v[i+1:]
}
}
for _, key := range keys {
if s := os.Getenv(key); s != "" {
return s
if v, ok := m[key]; ok {
return v
}
}
return ""
Expand Down

0 comments on commit 61222d3

Please sign in to comment.