Skip to content

Rework config.ini path handling #761

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

Merged
merged 9 commits into from
Feb 9, 2023
Prev Previous commit
Next Next commit
fine-tune a config searching and parsing
  • Loading branch information
umbynos authored and cmaglie committed Jan 27, 2023
commit e8b148ea6ba9382ea1ce644f38e723f72c3e52b2
27 changes: 15 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,14 @@ func loop() {
src, _ := os.Executable()
srcPath := paths.New(src)
srcDir := srcPath.Parent()
log.Print(srcPath)
log.Print(srcDir)

configPath := srcDir.Join("config.ini")
log.Print(configPath)

if configPath.NotExist() {
// probably we are on macOS, where the config is in a different dir
configPath = srcDir.Parent().Join("Resources", "config.ini")
if configPath.NotExist() {
log.Panic("config.ini file not found")
log.Panicf("config.ini file not found in %s", configPath)
}
}

Expand All @@ -208,17 +205,23 @@ func loop() {
if err != nil {
log.Panicf("cannot parse arguments: %s", err)
}
log.Infof("using config from %s", configPath)

// Parse additional ini config if defined
if len(*additionalConfig) > 0 {
log.Print(*additionalConfig)
args, err = parseIni(srcDir.Join(*additionalConfig).String())
if err != nil {
log.Panicf("additional config.ini cannot be parsed: %s", err)
}
err = iniConf.Parse(args)
if err != nil {
log.Panicf("cannot parse arguments: %s", err)
additionalConfigPath := paths.New(*additionalConfig)
if additionalConfigPath.NotExist() {
log.Infof("additional config file not found in %s", additionalConfigPath.String())
} else {
args, err = parseIni(additionalConfigPath.String())
if err != nil {
log.Panicf("additional config cannot be parsed: %s", err)
}
err = iniConf.Parse(args)
if err != nil {
log.Panicf("cannot parse arguments: %s", err)
}
log.Infof("using additional config from %s", additionalConfigPath.String())
}
}

Expand Down