Repository navigation
Conversation
find() reads the override map first (viper.go:1212) and the defaults map before the flag-default fallback (viper.go:1313), but the comment's list started at flag and omitted defaults. The Get doc a few hundred lines above (viper.go:712) already states the full order.
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.
What
The
find()doc comment lists the lookup order as "flag, env, config file, key/value store". The function consults two more sources, and the comment omits the one that comes first and the one that comes last-but-one.Why
find()walks, in this order (inline step comments are authoritative):viper.go:1212(// Set() override first)v.searchMap(v.override, path)viper.go:1221(// PFlag override next)viper.go:1271(// Env override next)viper.go:1295(// Config file next)viper.go:1304(// K/V store next)viper.go:1313(// Default next)v.searchMap(v.defaults, path)and only after all six, at
viper.go:1322-1324, the "Lastly … the flag's default value" fallback the comment already describes.So the list as written (a) starts at "flag" although
Set()overrides are consulted before it — which is exactly the precedence users trip over when aSet()value shadows a flag — and (b) never mentionsdefaults, which are consulted before the flag default.The same file already documents the complete order twice, in the package comment (
viper.go:75-81) and onGet(viper.go:703andviper.go:708-712: "override, flag, env, config file, key/value store, default"). Onlyfind()'s copy is short, so this brings one comment in line with the other two rather than inventing wording.Change
One comment line: the order list becomes
override, flag, env, config file, key/value store, default.Comment-only; no behavior change.Testing
gofmt-neutral (a line comment, no code or alignment touched) and no behavior change, somake lint/go test ./...were not re-run; I could not execute the Go toolchain in my environment. The order above is read directly fromfind()atmaster(528f741).Notes
Correction (body edit): my first version of this note said the PR was labelled
release-note/ignore. It is not — I have no triage permission on this repository, so I could not add the label, and the "Check minimum labels" step in.github/workflows/checks.yaml:16-33will stay red until a maintainer appliesrelease-note/ignore(or another accepted label) to this docs-only change.Relation to my other open PRs
Independent: #2170 rewords the remote-provider
SetConfigTypeexamples inREADME.md, #2167 documentsAutomaticEnv, #2166 the pflag wrappers, #2165DecodeHook's default — none touchfind()or the precedence list.Submitted with AI assistance; the doc/code discrepancy was verified line by line against
find()and theGet/package comments before opening.