Skip to content

Commit

Permalink
cleanup use of os.Environ() re-use env.List(prefix) (#5048)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored Sep 27, 2024
1 parent 97fe232 commit 609f32a
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions cmd/alias-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package cmd

import (
"fmt"
"os"
"sort"
"strings"

"github.com/minio/cli"
"github.com/minio/pkg/v3/console"
"github.com/minio/pkg/v3/env"

"github.com/fatih/color"
)
Expand Down Expand Up @@ -151,19 +151,13 @@ func listAliases(alias string, deprecated bool) (aliases []aliasMessage) {
}

// list alias from the environment variable.
for _, envLine := range os.Environ() {
pair := strings.SplitN(envLine, "=", 2)
if len(pair) != 2 {
for _, envK := range env.List(mcEnvHostPrefix) {
aliasCfg, _ := expandAliasFromEnv(env.Get(envK, ""))
if aliasCfg == nil {
continue
}
if len(strings.TrimPrefix(pair[0], mcEnvHostPrefix)) != 0 {
aliasCfg, _ := expandAliasFromEnv(pair[1])
if aliasCfg == nil {
continue
}
alias := strings.ReplaceAll(pair[0], mcEnvHostPrefix, "")
aliases = append(aliases, buildAliasMessage(alias, deprecated, aliasCfg))
}
alias := strings.ReplaceAll(envK, mcEnvHostPrefix, "")
aliases = append(aliases, buildAliasMessage(alias, deprecated, aliasCfg))
}

// list alias from the customized configuration.
Expand Down

0 comments on commit 609f32a

Please sign in to comment.