Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 689fc8b

Browse files
committedNov 29, 2022
fine-tune a config searching and parsing
1 parent 1342934 commit 689fc8b

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed
 

‎main.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,14 @@ func loop() {
186186
src, _ := osext.Executable()
187187
srcPath := paths.New(src)
188188
srcDir := srcPath.Parent()
189-
log.Print(srcPath)
190-
log.Print(srcDir)
191189

192190
configPath := srcDir.Join("config.ini")
193-
log.Print(configPath)
194191

195192
if configPath.NotExist() {
196193
// probably we are on macOS, where the config is in a different dir
197194
configPath = srcDir.Parent().Join("Resources", "config.ini")
198195
if configPath.NotExist() {
199-
log.Panic("config.ini file not found")
196+
log.Panicf("config.ini file not found in %s", configPath)
200197
}
201198
}
202199

@@ -209,17 +206,23 @@ func loop() {
209206
if err != nil {
210207
log.Panicf("cannot parse arguments: %s", err)
211208
}
209+
log.Infof("using config from %s", configPath)
212210

213211
// Parse additional ini config if defined
214212
if len(*additionalConfig) > 0 {
215-
log.Print(*additionalConfig)
216-
args, err = parseIni(srcDir.Join(*additionalConfig).String())
217-
if err != nil {
218-
log.Panicf("additional config.ini cannot be parsed: %s", err)
219-
}
220-
err = iniConf.Parse(args)
221-
if err != nil {
222-
log.Panicf("cannot parse arguments: %s", err)
213+
additionalConfigPath := paths.New(*additionalConfig)
214+
if additionalConfigPath.NotExist() {
215+
log.Infof("additional config file not found in %s", additionalConfigPath.String())
216+
} else {
217+
args, err = parseIni(additionalConfigPath.String())
218+
if err != nil {
219+
log.Panicf("additional config cannot be parsed: %s", err)
220+
}
221+
err = iniConf.Parse(args)
222+
if err != nil {
223+
log.Panicf("cannot parse arguments: %s", err)
224+
}
225+
log.Infof("using additional config from %s", additionalConfigPath.String())
223226
}
224227
}
225228

0 commit comments

Comments
 (0)
Please sign in to comment.