diff options
author | Robin Jarry <robin@jarry.cc> | 2022-11-15 22:53:20 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-11-16 16:12:11 +0100 |
commit | c016a51900bfb26b536621039320f2485061dfc2 (patch) | |
tree | 46ff535788275bcdb0294f7018644c8ef0aa04d2 /config | |
parent | f8e88632c49a4bd70efb503944f642e7daed37d8 (diff) | |
download | aerc-c016a51900bfb26b536621039320f2485061dfc2.tar.gz |
config: move [openers] parsing in separate file
The config.go file is getting too big. Move the aerc.conf [openers]
section parsing logic into a dedicated openers.go file.
No functional change.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'config')
-rw-r--r-- | config/config.go | 16 | ||||
-rw-r--r-- | config/openers.go | 29 |
2 files changed, 32 insertions, 13 deletions
diff --git a/config/config.go b/config/config.go index ef824279..20e28bd2 100644 --- a/config/config.go +++ b/config/config.go @@ -9,7 +9,6 @@ import ( "unicode" "github.com/go-ini/ini" - "github.com/google/shlex" "github.com/kyoh86/xdg" "github.com/mitchellh/go-homedir" @@ -117,17 +116,6 @@ func installTemplate(root, name string) error { } func (config *AercConfig) LoadConfig(file *ini.File) error { - if openers, err := file.GetSection("openers"); err == nil { - for mimeType, command := range openers.KeysHash() { - mimeType = strings.ToLower(mimeType) - if args, err := shlex.Split(command); err != nil { - return err - } else { - config.Openers[mimeType] = args - } - } - } - if triggers, err := file.GetSection("triggers"); err == nil { if err := triggers.MapTo(&config.Triggers); err != nil { return err @@ -186,6 +174,9 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) { if err := config.parseStatusline(file); err != nil { return nil, err } + if err := config.parseOpeners(file); err != nil { + return nil, err + } if err = config.LoadConfig(file); err != nil { return nil, err } @@ -196,7 +187,6 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) { return nil, err } - logging.Debugf("aerc.conf: [openers] %#v", config.Openers) logging.Debugf("aerc.conf: [triggers] %#v", config.Triggers) if err := config.parseTemplates(file); err != nil { diff --git a/config/openers.go b/config/openers.go new file mode 100644 index 00000000..d41c5455 --- /dev/null +++ b/config/openers.go @@ -0,0 +1,29 @@ +package config + +import ( + "strings" + + "git.sr.ht/~rjarry/aerc/logging" + "github.com/go-ini/ini" + "github.com/google/shlex" +) + +func (config *AercConfig) parseOpeners(file *ini.File) error { + openers, err := file.GetSection("openers") + if err != nil { + goto out + } + + for mimeType, command := range openers.KeysHash() { + mimeType = strings.ToLower(mimeType) + if args, err := shlex.Split(command); err != nil { + return err + } else { + config.Openers[mimeType] = args + } + } + +out: + logging.Debugf("aerc.conf: [openers] %#v", config.Openers) + return nil +} |