Repository navigation
Conversation
The comment described AutomaticEnv as matching env vars against existing keys and loading matches into Viper. find() does neither: it joins the requested key with the sub-name parents, upper-cases it through mergeWithEnvPrefix, applies the key replacer in getEnv and calls os.LookupEnv on every lookup (viper.go:1272-1282). Nothing is stored, so env-only keys stay out of AllKeys and AllSettings (viper.go:1970-1987).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview:
Corrects the
AutomaticEnvgodoc comment (both the package-level and the*Vipermethod copy) so it describes whatfind()actually does.What problem does it solve?:
The comment makes two claims that the code contradicts:
"check if environment variables match any of the existing keys (config, default or flags)" — the probe is not limited to keys that already exist.
find()builds the variable name from whatever key is being looked up, so anyGet/GetString/IsSetcall hits the environment:(
viper.go:1271-1278, and the inline comment says the opposite of the doc comment.)"they are loaded into Viper" — nothing is loaded.
AutomaticEnv()only flips a flag (viper.go:1460-1462), andgetEnvcallsos.LookupEnvon each lookup (viper.go:416-424).v.envis written only byBindEnv(viper.go:1163-1165), which is whyAllKeys()— and thereforeAllSettings()andWriteConfig()— never sees a key that exists only in the environment (viper.go:1980-1997).The new wording also states how the variable name is derived, since that is what a user actually needs: the key is upper-cased by
mergeWithEnvPrefix, prefixed with theSetEnvPrefixvalue when set (viper.go:389-395), and passed through theSetEnvKeyReplacervalue ingetEnvwhen set.No behaviour change, no API change — comment text only.
Special notes for a reviewer:
go build,go test, orgofmt(the sandbox refused them), so the change is reviewable on the cited lines alone. It is a comment edit; CI is the real check.gh search prs --repo spf13/viper AutomaticEnv --state openreturns only behaviour/feature PRs (Fix #1732 AutomaticEnv does not override Unmarshaled config slice values #1733, Add support for slices when using environement variables #1785, fix: apply envPrefix to all BindEnv variable names #1874, feat: handle other options for prefix #1719, fix: capitalize the second param in BindEnv #1397, Add example regarding required flags with Cobra + Viper #852), and the doc PRs I could see (doc: fix inverted wrap direction on FileNotFoundFromSearchError #2164, doc: DecodeHook's stated default is the hook the code replaced #2165, docs: clarify extensionless config handling and SetConfigType usage #2155, docs: fix typos in README.md and UPGRADE.md #2150, Fix "This is error wraps" doc typo on ConfigFileNotFoundError #2130) editerrors.go,viper.go:60, and the README/UPGRADE instead.README.md:259-260says "search for any environment variable prefixed and load them in", which has the same "load" imprecision. Happy to reword it in this PR if maintainers want the README synced too.viper.goline by line, and I am responsible for the result.