-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
git-like config: Allow .git/lab/lab config to override ~/.config/lab/lab #415
Comments
@prarit, two things:
Of course it would be better to have the option of using viper to do that, but what do you think about this approach while viper doesn't have it? |
Hah :) Thanks. I didn't have a chance to go back and think about it.
I think that would work. I was debating about using viper.UnMarshall() in the #414 but wanted to concentrate on using toml first.
|
After looking at the viper code, this works for my config examples above.
|
Ah, nice! Simpler and cleaner :) |
Today there are three ways to get core config data:
I propose to change this to a more git-like experience of
This would allow, for example, a ~/.config/lab/lab.toml of [core] comments = "true" and a .git/lab/show_metadata.toml of comments = "false" then the .git/lab/show_metadata.toml would override the ~/.config/lab/lab.toml I'm working on some code atm and should have a MR available in the next few days as a WIP. |
Just for the record, in the config overall you added loading of config files from the I think this issue and the above comment is entirely related to the desired new merge functionality? |
Yup, this issue and the above comment is related to the desired new merge functionality. |
@prarit where did we land on this? |
As stated in #414 I'd like to allow overrides between the global (~/.config/lab/lab) and local git-tree (.git/lab/lab) configs. There is a problem with the way viper works that prevents us from doing this and viper would need to be modified with a new function.
Suppose I have two config files with the same name but in different directories:
.first/lab with contents
and .second/lab with contents
and the following program that attempts to merge the configs:
The expected output is:
However the actual output is
This occurs because of the way viper searches for the config file: The two AddConfigPath() calls results in a search path of [.first .second] for a file 'lab'. MergeInConfig() will merge in the first match and it will not be .second/lab, but .first/lab. IOW, because the file name is the same the .second/lab is never found by MergeInConfig.
The only way to fix this is to add functionality for a RemoveConfigPath() to viper:
I thought about changing the code for MergeInConfig(), however, deemed it too risky to existing users to change the behavior to a last-found-first approach.
In any case I'm going to have to solve the viper issue before I can solve number 3 in #407.
The text was updated successfully, but these errors were encountered: