Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup use of os.Environ() re-use env.List(prefix) #5048

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading