2019-02-26 18:41:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-11-06 17:50:36 +00:00
|
|
|
"git.sp4ke.xyz/sp4ke/gomark/config"
|
|
|
|
"git.sp4ke.xyz/sp4ke/gomark/utils"
|
2019-02-27 10:47:06 +00:00
|
|
|
)
|
2019-02-26 18:41:02 +00:00
|
|
|
|
2022-10-23 13:08:06 +00:00
|
|
|
func initDefaultConfig() {
|
2019-02-27 10:47:06 +00:00
|
|
|
//TODO: handle chrome
|
2019-02-26 18:41:02 +00:00
|
|
|
log.Debug("Creating default config on config.toml")
|
|
|
|
|
2019-02-27 10:47:06 +00:00
|
|
|
err := config.InitConfigFile()
|
2019-02-26 18:41:02 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-23 13:08:06 +00:00
|
|
|
// FIX: make config init manual from main package
|
|
|
|
// HACK: this section is called well before module options/config parameters are
|
|
|
|
// initialized
|
|
|
|
func initConfig() {
|
2022-11-01 22:17:46 +00:00
|
|
|
log.Debugf("initializing config")
|
2019-02-27 10:47:06 +00:00
|
|
|
|
|
|
|
// Check if config file exists
|
|
|
|
exists, err := utils.CheckFileExists(config.ConfigFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !exists {
|
2022-10-23 13:08:06 +00:00
|
|
|
// Initialize default initConfig
|
2022-11-01 22:17:46 +00:00
|
|
|
//NOTE: if custom flags are passed before config.toml exists, falg
|
|
|
|
//options will not be saved to the initial config.toml, this means
|
|
|
|
//command line flags have higher priority than config.toml
|
2022-10-23 13:08:06 +00:00
|
|
|
initDefaultConfig()
|
2019-02-27 10:47:06 +00:00
|
|
|
} else {
|
2019-02-27 16:09:33 +00:00
|
|
|
err = config.LoadFromTomlFile()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2019-02-27 10:47:06 +00:00
|
|
|
}
|
2019-02-26 18:41:02 +00:00
|
|
|
|
|
|
|
}
|