-
Notifications
You must be signed in to change notification settings - Fork 50
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
Add the current executable dir to the config load path #350
Conversation
I tried to handle this in the adwatchd code by only calling |
Yeah, I’m thinking again about that one. Do we really need it? Like if you pass: For interactive configuration, I would expect foo to exist, then, you prefill the first field entry with it (as it’s the config you want to change). I don’t think we should use that just to prefill the first field entry without the configuration existing beforehand. Am I missing anything obvious? |
@didrocks the issue is that we set a default value for the a.rootCmd.PersistentFlags().StringP(
"config",
"c",
defaultConfigPath(), // the executable directory of the app
i18n.G("`path` to config file"),
) We can switch to using the vip.AddConfigPath("./")
vip.AddConfigPath("$HOME/")
vip.AddConfigPath("/etc/") I managed to get this to work for our case by prepending the executable's directory to viper's searched paths: vip.SetConfigName(name)
binPath, err := os.Executable()
if err != nil {
log.Warningf(context.Background(), i18n.G("failed to get executable path, not adding it as a config dir: %v"), err)
} else {
vip.AddConfigPath(filepath.Dir(binPath))
}
vip.AddConfigPath("./")
vip.AddConfigPath("$HOME/")
vip.AddConfigPath("/etc/") Does this seem more reasonable? |
It's good to have in mind that, as I mentioned here, the only cases where it's possible for the user to not pass in an explicit config file are:
If the service is installed, either interactively or through |
Ah, I do remember now :) < your other proposal >
It really does to me. This is in line with the path search of local/home/global. Just a note: I would add it after "/etc" to me. ("." is first)
Yes, until an admin mess with the windows service manager UI :) |
Hehe, for better or worse they actually can't. Due to kardianos/service#82 changes made to the arguments in the Services GUI are not reflected in the actual service. |
waow, indeed :) ok I still think your second proposal is better after all. |
Sounds good I'll implement that then! |
ad95fb4
to
b313fa9
Compare
0cb8d67
to
04923cf
Compare
Codecov Report
@@ Coverage Diff @@
## main #350 +/- ##
==========================================
- Coverage 84.45% 84.40% -0.06%
==========================================
Files 57 57
Lines 3925 3930 +5
==========================================
+ Hits 3315 3317 +2
- Misses 387 388 +1
- Partials 223 225 +2
Continue to review full report at Codecov.
|
04923cf
to
5faaa4b
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.
One small change now that the formatting pass (and I’m sure the test will pass ;)
@@ -108,6 +109,12 @@ func TestInit(t *testing.T) { | |||
configFileContent: "value: filecontentvalue", | |||
want: "filecontentvalue", wantCallbackCalled: 1, | |||
}, | |||
"Load configuration from executable dir": { |
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.
With a test without asking! You got the spirit :) \o/
In adwatchd we would like to use the executable directory as the default config path. Update the config API to add the executable path to the config search path, after all the other paths.
5faaa4b
to
359ac46
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.
I will surely enjoy the "new content" :)
In adwatchd we would like to use the executable directory as the default config path.
Update the config API to add the executable path to the config search path, after all the other paths.