summaryrefslogtreecommitdiff
path: root/cmd/main.go
diff options
context:
space:
mode:
authorEvan Van Dam <evandam92@gmail.com>2023-09-06 19:19:24 -0700
committerGitHub <noreply@github.com>2023-09-07 02:19:24 +0000
commitf2ab7099db6d8386299796e6eef8e30f65b21bcc (patch)
tree6b57a377f84eb921f91a76ff5e9fb07e385fb39a /cmd/main.go
parent50cea4e26369b1c5049e8539d6c2bbdac11b3754 (diff)
cmd: Prevent overwriting existing env vars with `--envfile` (#5803)
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
Diffstat (limited to 'cmd/main.go')
-rw-r--r--cmd/main.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/cmd/main.go b/cmd/main.go
index 1d6478a..b4e3fdc 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -300,8 +300,12 @@ func loadEnvFromFile(envFile string) error {
}
for k, v := range envMap {
- if err := os.Setenv(k, v); err != nil {
- return fmt.Errorf("setting environment variables: %v", err)
+ // do not overwrite existing environment variables
+ _, exists := os.LookupEnv(k)
+ if !exists {
+ if err := os.Setenv(k, v); err != nil {
+ return fmt.Errorf("setting environment variables: %v", err)
+ }
}
}