Change check of existing env to respect empty (but set) vars.

respect_empty_external_env_vars
John Barton (joho) 2017-03-28 11:54:56 +11:00
parent cd1272609d
commit 034acc2190
1 changed files with 8 additions and 1 deletions

View File

@ -119,8 +119,15 @@ func loadFile(filename string, overload bool) error {
return err
}
currentEnv := map[string]bool{}
rawEnv := os.Environ()
for _, rawEnvLine := range rawEnv {
key := strings.Split(rawEnvLine, "=")[0]
currentEnv[key] = true
}
for key, value := range envMap {
if os.Getenv(key) == "" || overload {
if !currentEnv[key] || overload {
os.Setenv(key, value)
}
}