-
Notifications
You must be signed in to change notification settings - Fork 160
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
Refactor main flags as settings.Settings #1952
Conversation
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.
The refactoring makes sense to me and makes main.go a lot easier to read. LGTM!
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.
Big ups for removing code from main and making things testable 👍
LGTM
internal/settings/settings.go
Outdated
func (f *flags) ResolverURIs() []string { | ||
var configPaths []string | ||
if configPaths = f.configPaths.value; len(configPaths) == 0 { | ||
if configEnvVal := os.Getenv(ConfigEnvVarName); len(configEnvVal) != 0 { |
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.
Long term, might be nice to separate Getenv and Setenv from the settings code since reading/writing them is effectively I/O, and instead pass this information around in some kind of abstraction that could be swappable for testing. Removes the need to deal with global (env) variables in tests.
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.
A thought/goal I've had is to determine a clear setting precedence of cli arg > env var > default that allows easily registering a new setting, readme update, and adding (to) an associated test. This would require settings reading the env though. Ideally there wouldn't be any side effects from setting values unless the only way to advertise their existence downstream is through the env. The final env interface could be something like Env() map[string]string
that main or an applicable component would be responsible for actually sourcing to the environment*.
8669f42
to
22e83e3
Compare
22e83e3
to
140b8c5
Compare
* Refactor service flags as Settings * Remove test config locations as valid defaults
These changes move existing main and
flags
option parsing, env var evaluation/setting, and default logic to a new internalsettings
package where a more minimalSettings
interface is used to populate the underlying config provider resolver settings and command line argument adjustment. They are largely attempted to be noops/transparent readability and logic changes with some test practices improvements except for:VarP
helpers for version and help shorthands and not have to track with all collector flag names (something we're most likely failing to do already).cmd/
-rooted locationI didn't change the bulk of the config and memory ballast logic to keep the change set more manageable and the likelihood of introducing bugs down, but think it could benefit from an overhaul in subsequent changes.*