aboutsummaryrefslogtreecommitdiffstats
path: root/config/general.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-11-15 00:22:55 +0100
committerRobin Jarry <robin@jarry.cc>2022-11-16 16:12:01 +0100
commiteb10c328fd8953f4a2cc7d22126f4214a57c9261 (patch)
tree76381ba24bdb33c7cb0cba4edfa81cf6bfa11996 /config/general.go
parent21f82053075b320015ac622c683aafeac2b0a041 (diff)
downloadaerc-eb10c328fd8953f4a2cc7d22126f4214a57c9261.tar.gz
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 <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'config/general.go')
-rw-r--r--config/general.go48
1 files changed, 48 insertions, 0 deletions
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")
+ }
+}