Add .env file support#8
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8 +/- ##
==========================================
+ Coverage 23.87% 26.35% +2.48%
==========================================
Files 1 1
Lines 155 148 -7
==========================================
+ Hits 37 39 +2
+ Misses 105 96 -9
Partials 13 13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@cursor review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 19d395c. Configure here.
| // set value to field. | ||
| if err := encode.SetField(field, envVal, vStruct.Type().Field(i)); err != nil { | ||
| return fmt.Errorf("'%s' from '%s' cannot be set to %s (%s)", envVal, name, vStruct.Type().Field(i).Name, field.Type()) | ||
| return fmt.Errorf("'%s' from '%s' cannot be set to %s (%s) %v", envVal, name, vStruct.Type().Field(i).Name, field.Type(), err) |
There was a problem hiding this comment.
Nested struct env mapping removed
High Severity
Decoder.Unmarshal no longer recurses into nested structs or applies env prefixes / omitprefix, after populate was removed. Nested fields (e.g. LEVEL2_*, embedded structs, documented omitprefix layouts) are not filled from the environment unless the parent struct implements encoding.TextUnmarshaler.
Reviewed by Cursor Bugbot for commit 19d395c. Configure here.
- New envFile Option


Quality check
Summary
Adds support for loading a working-directory
.envfile whenOptEnvis enabled, alongside existing environment-variable mapping.internal/encode/env/dotenv.go) with quoted-value handling and inline-comment trimming; a follow-up commit tightens quote edge cases.Load/LoadEnvnow apply.envvalues per struct field (non-empty.enventries overrideos.Getenvfor that key) before file and flag sources.config.goload-order comments.dotenv_test.goand related env tests; refreshes fixture configs undertest/.Note
Medium Risk
Changes how environment-style config is decoded (flat
GetValvs prior nested env mapping) and introduces new parsing rules that affect load order and field population when.envorOptEnvis used.Overview
Adds a dotenv parser and wires
.envfiles into config loading:file.Loadand-cpaths with a.envextension useLoadEnvFile, which parses keys/values (quotes, escapes, inline comments) and maps them through the envDecodervia an injectableGetValhook.The env decoder now resolves values through
GetVal(defaultos.Getenv) instead of the old recursivepopulatehelper; env encode quotes strings when needed. Public docs describe cwd.envunderOptEnv/LoadEnv, and tests/fixtures cover dotenv parsing plus loadingtest/.env. CI bumps Go versions (modulego 1.18, trialv0.8.0).Reviewed by Cursor Bugbot for commit 19d395c. Bugbot is set up for automated code reviews on this repo. Configure here.