From eb10c328fd8953f4a2cc7d22126f4214a57c9261 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 15 Nov 2022 00:22:55 +0100 Subject: config: move [general] parsing in separate file The config.go file is getting too big. Move the aerc.conf [general] section parsing logic into a dedicated general.go file. No functional change. Signed-off-by: Robin Jarry Acked-by: Moritz Poldrack --- config/general.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 config/general.go (limited to 'config/general.go') diff --git a/config/general.go b/config/general.go new file mode 100644 index 00000000..7f8ed2ef --- /dev/null +++ b/config/general.go @@ -0,0 +1,48 @@ +package config + +import ( + "fmt" + + "git.sr.ht/~rjarry/aerc/logging" + "github.com/go-ini/ini" +) + +type GeneralConfig struct { + DefaultSavePath string `ini:"default-save-path"` + PgpProvider string `ini:"pgp-provider"` + UnsafeAccountsConf bool `ini:"unsafe-accounts-conf"` +} + +func defaultGeneralConfig() GeneralConfig { + return GeneralConfig{ + PgpProvider: "internal", + UnsafeAccountsConf: false, + } +} + +func (config *AercConfig) parseGeneral(file *ini.File) error { + gen, err := file.GetSection("general") + if err != nil { + goto end + } + + if err := gen.MapTo(&config.General); err != nil { + return err + } + if err := config.General.validatePgpProvider(); err != nil { + return err + } + +end: + logging.Debugf("aerc.conf: [general] %#v", config.General) + return nil +} + +func (gen *GeneralConfig) validatePgpProvider() error { + switch gen.PgpProvider { + case "gpg", "internal": + return nil + default: + return fmt.Errorf("pgp-provider must be either gpg or internal") + } +} -- cgit