From 378b9dd29e1602a06a95acab5d2eda648f5ff3e8 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 4 Sep 2019 13:48:30 -0400 Subject: [PATCH] Remove ability to have duplicates in environment variables Signed-off-by: Matt Farina --- cmd/helm/env.go | 4 ++-- pkg/cli/environment.go | 17 ++++------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/cmd/helm/env.go b/cmd/helm/env.go index 7c09d1632..469ec364b 100644 --- a/cmd/helm/env.go +++ b/cmd/helm/env.go @@ -55,8 +55,8 @@ type envOptions struct { } func (o *envOptions) run(out io.Writer) error { - for _, e := range o.settings.EnvironmentVariables { - fmt.Printf("%s=\"%s\" \n", e.Name, e.Value) + for k, v := range o.settings.EnvironmentVariables { + fmt.Printf("%s=\"%s\" \n", k, v) } return nil } diff --git a/pkg/cli/environment.go b/pkg/cli/environment.go index 6b3c4d333..375726714 100644 --- a/pkg/cli/environment.go +++ b/pkg/cli/environment.go @@ -52,13 +52,8 @@ type EnvSettings struct { // PluginsDirectory is the path to the plugins directory. PluginsDirectory string - // Environment Variables Store - EnvironmentVariables []EnvironmentVariable -} - -type EnvironmentVariable struct { - Name string - Value string + // Environment Variables Store. + EnvironmentVariables map[string]string } func New() *EnvSettings { @@ -67,7 +62,7 @@ func New() *EnvSettings { RegistryConfig: helmpath.ConfigPath("registry.json"), RepositoryConfig: helmpath.ConfigPath("repositories.yaml"), RepositoryCache: helmpath.CachePath("repository"), - EnvironmentVariables: []EnvironmentVariable{}, + EnvironmentVariables: make(map[string]string), } envSettings.setHelmEnvVars() return &envSettings @@ -118,11 +113,7 @@ func (s *EnvSettings) setHelmEnvVars() { if eVal := os.Getenv(key); len(eVal) > 0 { val = eVal } - s.EnvironmentVariables = append(s.EnvironmentVariables, - EnvironmentVariable{ - Name: key, - Value: val, - }) + s.EnvironmentVariables[key] = val } }