-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
enhancement: Expand with default values #285
enhancement: Expand with default values #285
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #285 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 464 477 +13
=========================================
+ Hits 464 477 +13
☔ View full report in Codecov by Sentry. |
Made a small note only. Could you also note this new feature somewhere in the readme? Thanks for the PR 🙏 |
Sure! |
I added an example covering common cases (using envDefault, and envDefault being overrided) |
amazing, thank you! |
* dx: getOr return redability * feat: expand with defaults * fix: rm unnecessary guard * docs: update readme - expand with envdefault * chore: rm readme extra spaces --------- Co-authored-by: Gabriel F Cipriano <[email protected]>
resolves #279 (and resolves #250 (?))
Approach:
To capture the default values when expanding envs, we need to somehow have access to the previously resolved variables.
So, the
get()
function needs an auxiliar data structure (map[string]string
) that will keep track of the resolved raw strings. In that way, we can take advange ofos.Expand(s string, mapping func(string) string)
to provide our own mapping function that returns the resolved string value for a given key.To avoid passing this auxiliar data structure as a parameter down the function calls, I added it as an unexported field of the Options struct, let's say, using
opts
as if it were actx
.I'm not really sure if it's the best way of doing this, any suggestions will be more than appreciated!
edit: typo