1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-07-03 11:53:41 +02:00

cmd/thalos/server.go: define and use ReadConfig() that utilizes Config.ReadFile and Config.ReadCliFlags() methods

This commit is contained in:
Henrik Hautakoski 2024-02-12 15:14:21 +01:00
parent 4a5cff20cd
commit 457e0e4eeb

View file

@ -7,7 +7,6 @@ import (
"io" "io"
"os" "os"
"os/signal" "os/signal"
"path"
"syscall" "syscall"
"time" "time"
@ -223,6 +222,20 @@ func stateSaver(state app.State) error {
return cache.Set(ctx, "state", state, 0) return cache.Set(ctx, "state", state, 0)
} }
func ReadConfig(cfg *config.Config, ctx *cli.Context) error {
// Read file first.
if err := cfg.ReadFile(ctx.Path("config")); err != nil {
return err
}
// Then override any cli flags
if err := cfg.ReadCliFlags(ctx); err != nil {
return err
}
return nil
}
func serverCmd(ctx *cli.Context) error { func serverCmd(ctx *cli.Context) error {
var err error var err error
var chainInfo *eos.InfoResp var chainInfo *eos.InfoResp
@ -242,15 +255,8 @@ func serverCmd(ctx *cli.Context) error {
// Parse config // Parse config
conf = config.New() conf = config.New()
if err = conf.ReadFile(ctx.Path("config")); err != nil { if err = ReadConfig(&conf, ctx); err != nil {
return err return fmt.Errorf("config: %s", err)
}
// If log file is given on the commandline, override config values.
logFile := ctx.Path("log")
if len(logFile) > 0 {
conf.Log.Directory = path.Dir(logFile)
conf.Log.Filename = path.Base(logFile)
} }
lvl, err := log.ParseLevel(ctx.String("level")) lvl, err := log.ParseLevel(ctx.String("level"))