-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
feat: configuration source precedence #980
Conversation
f905f1a
to
c88b984
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool! My only overall gripe is how much we're relying on yaml un/marshaling to implement the defaults and flag overrides. I found that it made it harder for me to understand what was going on; is there no better way of doing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
Broke it afterwards, re-review required anyways
Re-wrote and drastically simplified the Added tests for precedence as well, to make sure it all works as expected. Mind having a look @rfratto @cyriltovena @slim-bean? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thanks for taking the time to make the implementation easier to understand.
When someone approves this, can you hold off on merging until #1062 gets merged? Joe is working hard to move us over to modules and he asked us to hold off on changing Gopkg.lock
No need to do that, not even modifying dependencies here, we can discard these autogenerated changes of |
ca28e5e
to
b6219de
Compare
Adds configuration package for managing various configuration sources with correct precedence
Not immediately needed and easy to reimplement, removed for now
Adds a convenience wrapper `cfg.Parse()` which unmarshals from flag and yaml
Adds tests for Parse(), furthermore introduces FlagDefaults, a safer wrapper for FlagDefaultsDangerous that fails when dst is not zero valued.
Previously, the flag functionality relied on comparing archived defaults with the merged data after flag.Parse(). This inevitably led to a bug, that this package was able to decide whether a value is on default, or set by user to the same as default. This meant the user value was always lost. This now switches it to a more traditional usage of the flag package: 1. flag.***Var already sets the default value on the pointer 2. intermediate sources can make changes here 3. flag.Parse() ONLY sets new values
This reverts commit 9b1b6d39ac00be9e992fd35f371c7c64b005719b.
Adds tests to ensure precendence is working correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Implements a more sophisticated approach on config source precedence. Rules are
as follows:
.yaml
-fileSome hacking had to be done to separate defaults from actual flag values to notoverwrite the yaml contents. See the excessive use of
yaml.(Un)marshal
.If a better approach is known, I am happy to take it.
Note: This is resolved now, removed that
Multiple tests have been added as well to make dead sure this package behaves as desired.