Repository navigation
fix(config): make every config key environment-overridable - #98
Merged
Merged
Conversation
DOT_ env overrides were driven by four hand-lists that had to agree (the BindEnv whitelist, the per-section env readers, the zero-value merge functions, and the struct itself) and did not: unlisted keys such as dotfile.package_name_mapping, symlinks.backup_dir, output.table_style, and the whole update and network sections were silently ignored, and the sparse-overlay merge could never propagate an env boolean set to false over a file value of true. Environment bindings are now derived by reflection from the config struct's mapstructure tags, and overrides are applied directly onto the loaded configuration under viper's IsSet, so explicit false survives. Path-typed values expand tilde and $VAR at apply time through the same ordered field list ExpandPaths uses. List values are comma-separated, matching the documented contract and the config set convention, where viper's own env handling would whitespace-split. A reflection-driven test walks every struct key and proves its env form lands, with a guard against vacuous samples, so a future key cannot ship silently unbound. Docs that enumerated the old partial binding list now state the uniform rule. Fixes #86
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.
Summary
Fixes #86.
DOT_ env overrides were driven by four hand-lists that had to agree (the BindEnv whitelist, the per-section env readers, the zero-value merge functions, and the struct itself) and did not:
dotfile.package_name_mapping(the reported key),symlinks.backup_dir,output.table_style, and the entireupdateandnetworksections.falsecould never override a file value oftrue.DOT_SYMLINKS_FOLDING=falseandDOT_DOTFILE_TRANSLATE=falsewere also silent no-ops even though they were bound and read.Changes
IsSet, replacing the sparse-config merge; explicitfalsenow survives. The env-onlymergeConfigspath is deleted; the flags path is untouched (its residual issues are filed as Loader.LoadWithFlags is production-dead and its flag merge cannot represent explicit false #97).~/$VARthrough the same orderedpathFieldslistExpandPathsuses (shared list, deterministic error attribution).config setconvention; viper alone would whitespace-split, turning the documentedDOT_IGNORE_PATTERNS="*.log,*.tmp"example into one bogus pattern.Tests
TestLoader_EnvOverridesEveryConfigKey: reflection walk over every struct key, one valid non-default sample each (vacuous samples rejected), proving each env form lands. Mutation-checked: removing keys from the apply maps fails exactly those subtests.TestLoader_EnvFalseOverridesFileTrue: the exact issue repro shape.TestLoader_EnvListValuesAreCommaSeparated.Verified end to end with a built binary:
DOT_DOTFILE_PACKAGE_NAME_MAPPING=falsenow overrides both the default and an explicit filetrue. Full suite green with race and coverage; golangci-lint clean.