2024-04-07 12:11:25 +07:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2024-04-26 22:13:04 +07:00
|
|
|
"fmt"
|
|
|
|
|
2024-04-07 12:11:25 +07:00
|
|
|
"github.com/adrg/xdg"
|
2024-04-08 16:59:42 +07:00
|
|
|
"github.com/joho/godotenv"
|
2024-04-07 12:11:25 +07:00
|
|
|
"github.com/tigorlazuardi/redmage/config"
|
|
|
|
"github.com/tigorlazuardi/redmage/pkg/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
var cfg *config.Config
|
|
|
|
|
|
|
|
func initConfig() {
|
2024-04-08 16:59:42 +07:00
|
|
|
_ = godotenv.Load()
|
|
|
|
|
2024-04-07 12:11:25 +07:00
|
|
|
xdgJson, _ := xdg.ConfigFile("redmage/config.json")
|
|
|
|
xdgYaml, _ := xdg.ConfigFile("redmage/config.yaml")
|
|
|
|
|
|
|
|
cfg = config.NewConfigBuilder().
|
|
|
|
LoadDefault().
|
|
|
|
LoadJSONFile("/etc/redmage/config.json").
|
|
|
|
LoadYamlFile("/etc/redmage/config.yaml").
|
|
|
|
LoadJSONFile(xdgJson).
|
|
|
|
LoadYamlFile(xdgYaml).
|
|
|
|
LoadJSONFile("config.json").
|
|
|
|
LoadYamlFile("config.yaml").
|
|
|
|
LoadEnv().
|
|
|
|
LoadFlags(RootCmd.PersistentFlags()).
|
|
|
|
Build()
|
|
|
|
|
2024-04-26 22:13:04 +07:00
|
|
|
fmt.Println("download.concurrency.subreddits", cfg.Get("download.concurrency.subreddits"))
|
|
|
|
fmt.Println("download.concurrency.images", cfg.Get("download.concurrency.images"))
|
|
|
|
|
2024-04-07 12:11:25 +07:00
|
|
|
handler := log.NewHandler(cfg)
|
|
|
|
log.SetDefault(handler)
|
|
|
|
}
|