1
0
Fork 0
mirror of https://git.sr.ht/~rjarry/aerc synced 2025-02-22 14:53:57 +01:00
aerc/config/reload.go
Koni Marti 50647d5895 config: add reload helper functions
Add reload helper function to reload config files. Store the initially
used config files for the reloading.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Inwit <inwit@sindominio.net>
Acked-by: Robin Jarry <robin@jarry.cc>
2024-08-20 12:26:46 +02:00

68 lines
1.2 KiB
Go

package config
import (
"errors"
"os"
"path/filepath"
"git.sr.ht/~rjarry/aerc/lib/log"
)
type reloadStore struct {
binds string
conf string
}
var rlst reloadStore
func SetBindsFilename(fn string) {
log.Debugf("reloader: set binds file: %s", fn)
rlst.binds = fn
}
func SetConfFilename(fn string) {
log.Debugf("reloader: set conf file: %s", fn)
rlst.conf = fn
}
func ReloadBinds() (string, error) {
f := rlst.binds
if !exists(f) {
return f, os.ErrNotExist
}
log.Debugf("reload binds file: %s", f)
Binds = defaultBindsConfig()
return f, parseBindsFromFile(filepath.Dir(f), f)
}
func ReloadConf() (string, error) {
f := rlst.conf
if !exists(f) {
return f, os.ErrNotExist
}
log.Debugf("reload conf file: %s", f)
General = new(GeneralConfig)
Filters = nil
Compose = new(ComposeConfig)
Converters = make(map[string]string)
Viewer = new(ViewerConfig)
Statusline = new(StatuslineConfig)
Openers = nil
Hooks = HooksConfig{}
Ui = defaultUIConfig()
Templates = new(TemplateConfig)
return f, parseConf(f)
}
func ReloadAccounts() error {
return errors.New("not implemented")
}
func exists(fn string) bool {
if _, err := os.Stat(fn); errors.Is(err, os.ErrNotExist) {
return false
}
return true
}