aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-11-15 00:36:56 +0100
committerRobin Jarry <robin@jarry.cc>2022-11-16 16:12:05 +0100
commitf96172f5064b7245dfdb766163ceee856e2ee51b (patch)
tree3eed51fd23255ca310ecfb3d9e988d914fe5b2b0
parent17bb9387c4a3ecab17ace3dc78694c2236a1024f (diff)
downloadaerc-f96172f5064b7245dfdb766163ceee856e2ee51b.tar.gz
config: move [compose] parsing in separate file
The config.go file is getting too big. Move the aerc.conf [compose] section parsing logic into a dedicated compose.go file. No functional change. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
-rw-r--r--config/compose.go59
-rw-r--r--config/config.go45
2 files changed, 63 insertions, 41 deletions
diff --git a/config/compose.go b/config/compose.go
new file mode 100644
index 00000000..31ee0a8b
--- /dev/null
+++ b/config/compose.go
@@ -0,0 +1,59 @@
+package config
+
+import (
+ "fmt"
+ "regexp"
+
+ "git.sr.ht/~rjarry/aerc/logging"
+ "github.com/go-ini/ini"
+)
+
+type ComposeConfig struct {
+ Editor string `ini:"editor"`
+ HeaderLayout [][]string `ini:"-"`
+ AddressBookCmd string `ini:"address-book-cmd"`
+ ReplyToSelf bool `ini:"reply-to-self"`
+ NoAttachmentWarning *regexp.Regexp `ini:"-"`
+}
+
+func defaultComposeConfig() ComposeConfig {
+ return ComposeConfig{
+ HeaderLayout: [][]string{
+ {"To", "From"},
+ {"Subject"},
+ },
+ ReplyToSelf: true,
+ }
+}
+
+func (config *AercConfig) parseCompose(file *ini.File) error {
+ compose, err := file.GetSection("compose")
+ if err != nil {
+ goto end
+ }
+
+ if err := compose.MapTo(&config.Compose); err != nil {
+ return err
+ }
+ for key, val := range compose.KeysHash() {
+ if key == "header-layout" {
+ config.Compose.HeaderLayout = parseLayout(val)
+ }
+
+ if key == "no-attachment-warning" && len(val) > 0 {
+ re, err := regexp.Compile("(?im)" + val)
+ if err != nil {
+ return fmt.Errorf(
+ "Invalid no-attachment-warning '%s': %w",
+ val, err,
+ )
+ }
+
+ config.Compose.NoAttachmentWarning = re
+ }
+ }
+
+end:
+ logging.Debugf("aerc.conf: [compose] %#v", config.Compose)
+ return nil
+}
diff --git a/config/config.go b/config/config.go
index dc749cf4..95bf8d43 100644
--- a/config/config.go
+++ b/config/config.go
@@ -2,11 +2,9 @@ package config
import (
"errors"
- "fmt"
"log"
"os"
"path"
- "regexp"
"strings"
"unicode"
@@ -18,14 +16,6 @@ import (
"git.sr.ht/~rjarry/aerc/logging"
)
-type ComposeConfig struct {
- Editor string `ini:"editor"`
- HeaderLayout [][]string `ini:"-"`
- AddressBookCmd string `ini:"address-book-cmd"`
- ReplyToSelf bool `ini:"reply-to-self"`
- NoAttachmentWarning *regexp.Regexp `ini:"-"`
-}
-
type ViewerConfig struct {
Pager string
Alternatives []string
@@ -171,28 +161,6 @@ func (config *AercConfig) LoadConfig(file *ini.File) error {
return err
}
}
- if compose, err := file.GetSection("compose"); err == nil {
- if err := compose.MapTo(&config.Compose); err != nil {
- return err
- }
- for key, val := range compose.KeysHash() {
- if key == "header-layout" {
- config.Compose.HeaderLayout = parseLayout(val)
- }
-
- if key == "no-attachment-warning" && len(val) > 0 {
- re, err := regexp.Compile("(?im)" + val)
- if err != nil {
- return fmt.Errorf(
- "Invalid no-attachment-warning '%s': %w",
- val, err,
- )
- }
-
- config.Compose.NoAttachmentWarning = re
- }
- }
- }
if triggers, err := file.GetSection("triggers"); err == nil {
if err := triggers.MapTo(&config.Triggers); err != nil {
@@ -255,14 +223,7 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) {
DisplayMode: "",
},
- Compose: ComposeConfig{
- HeaderLayout: [][]string{
- {"To", "From"},
- {"Subject"},
- },
- ReplyToSelf: true,
- },
-
+ Compose: defaultComposeConfig(),
Templates: defaultTemplatesConfig(),
Openers: make(map[string][]string),
}
@@ -270,6 +231,9 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) {
if err := config.parseFilters(file); err != nil {
return nil, err
}
+ if err := config.parseCompose(file); err != nil {
+ return nil, err
+ }
if err = config.LoadConfig(file); err != nil {
return nil, err
}
@@ -282,7 +246,6 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) {
logging.Debugf("aerc.conf: [statusline] %#v", config.Statusline)
logging.Debugf("aerc.conf: [viewer] %#v", config.Viewer)
- logging.Debugf("aerc.conf: [compose] %#v", config.Compose)
logging.Debugf("aerc.conf: [openers] %#v", config.Openers)
logging.Debugf("aerc.conf: [triggers] %#v", config.Triggers)