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

pkg/flags: warns on shadowed environment variable flags #8385

Merged
merged 1 commit into from
Aug 14, 2017
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
6 changes: 3 additions & 3 deletions pkg/flags/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ func SetFlagsFromEnv(prefix string, fs *flag.FlagSet) error {
fs.VisitAll(func(f *flag.Flag) {
err = setFlagFromEnv(fs, prefix, f.Name, usedEnvKey, alreadySet, true)
})

verifyEnv(prefix, usedEnvKey, alreadySet)

return err
}

Expand All @@ -100,6 +98,7 @@ func SetPflagsFromEnv(prefix string, fs *pflag.FlagSet) error {
err = serr
}
})
verifyEnv(prefix, usedEnvKey, alreadySet)
return err
}

Expand All @@ -118,7 +117,8 @@ func verifyEnv(prefix string, usedEnvKey, alreadySet map[string]bool) {
continue
}
if alreadySet[kv[0]] {
plog.Infof("recognized environment variable %s, but unused: shadowed by corresponding flag ", kv[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be staged as a deprecated warning in 3.3 and then finally fully error out in 3.4?

// TODO: exit with error in v3.4
plog.Warningf("recognized environment variable %s, but unused: shadowed by corresponding flag", kv[0])
continue
}
if strings.HasPrefix(env, prefix+"_") {
Expand Down