diff options
-rw-r--r-- | config/accounts.go | 32 | ||||
-rw-r--r-- | config/binds.go | 29 | ||||
-rw-r--r-- | config/config.go | 44 |
3 files changed, 63 insertions, 42 deletions
diff --git a/config/accounts.go b/config/accounts.go index 1afa77c4..ac0a5444 100644 --- a/config/accounts.go +++ b/config/accounts.go @@ -120,18 +120,7 @@ const ( var Accounts []*AccountConfig -func parseAccounts(root string, accts []string, filename string) error { - if filename == "" { - filename = path.Join(root, "accounts.conf") - err := checkConfigPerms(filename) - if errors.Is(err, os.ErrNotExist) { - // No config triggers account configuration wizard - return nil - } else if err != nil { - return err - } - } - +func parseAccountsFromFile(root string, accts []string, filename string) error { log.Debugf("Parsing accounts configuration from %s", filename) file, err := ini.LoadSources(ini.LoadOptions{ @@ -188,6 +177,25 @@ If you want to disable STARTTLS, append +insecure to the schema. return nil } +func parseAccounts(root string, accts []string, filename string) error { + if filename == "" { + filename = path.Join(root, "accounts.conf") + err := checkConfigPerms(filename) + if errors.Is(err, os.ErrNotExist) { + // No config triggers account configuration wizard + return nil + } else if err != nil { + return err + } + } + + if err := parseAccountsFromFile(root, accts, filename); err != nil { + return fmt.Errorf("%s: %w", filename, err) + } + + return nil +} + func ParseAccountConfig(name string, section *ini.Section) (*AccountConfig, error) { account := AccountConfig{ Name: name, diff --git a/config/binds.go b/config/binds.go index bedc6d9a..b65aa1ab 100644 --- a/config/binds.go +++ b/config/binds.go @@ -101,16 +101,7 @@ func defaultBindsConfig() *BindingConfig { var Binds = defaultBindsConfig() -func parseBinds(root string, filename string) error { - if filename == "" { - filename = path.Join(root, "binds.conf") - if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) { - fmt.Printf("%s not found, installing the system default\n", filename) - if err := installTemplate(root, "binds.conf"); err != nil { - return err - } - } - } +func parseBindsFromFile(root string, filename string) error { log.Debugf("Parsing key bindings configuration from %s", filename) binds, err := ini.LoadSources(ini.LoadOptions{ KeyValueDelimiters: "=", @@ -155,6 +146,24 @@ func parseBinds(root string, filename string) error { return nil } +func parseBinds(root string, filename string) error { + if filename == "" { + filename = path.Join(root, "binds.conf") + if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) { + fmt.Printf("%s not found, installing the system default\n", filename) + if err := installTemplate(root, "binds.conf"); err != nil { + return err + } + } + } + + if err := parseBindsFromFile(root, filename); err != nil { + return fmt.Errorf("%s: %w", filename, err) + } + + return nil +} + func LoadBindingSection(sec *ini.Section) (*KeyBindings, error) { bindings := NewKeyBindings() for key, value := range sec.KeysHash() { diff --git a/config/config.go b/config/config.go index 1efbf896..61ac041e 100644 --- a/config/config.go +++ b/config/config.go @@ -77,31 +77,13 @@ func installTemplate(root, name string) error { return nil } -func LoadConfigFromFile( - root *string, accts []string, filename, bindPath, acctPath string, -) error { - if root == nil { - _root := xdg.ConfigPath("aerc") - root = &_root - } - if filename == "" { - filename = path.Join(*root, "aerc.conf") - // if it doesn't exist copy over the template, then load - if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) { - fmt.Printf("%s not found, installing the system default\n", filename) - if err := installTemplate(*root, "aerc.conf"); err != nil { - return err - } - } - } - +func parseConf(filename string) error { file, err := ini.LoadSources(ini.LoadOptions{ KeyValueDelimiters: "=", }, filename) if err != nil { return err } - if err := parseGeneral(file); err != nil { return err } @@ -132,13 +114,35 @@ func LoadConfigFromFile( if err := parseTemplates(file); err != nil { return err } + return nil +} + +func LoadConfigFromFile( + root *string, accts []string, filename, bindPath, acctPath string, +) error { + if root == nil { + _root := xdg.ConfigPath("aerc") + root = &_root + } + if filename == "" { + filename = path.Join(*root, "aerc.conf") + // if it doesn't exist copy over the template, then load + if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) { + fmt.Printf("%s not found, installing the system default\n", filename) + if err := installTemplate(*root, "aerc.conf"); err != nil { + return err + } + } + } + if err := parseConf(filename); err != nil { + return fmt.Errorf("%s: %w", filename, err) + } if err := parseAccounts(*root, accts, acctPath); err != nil { return err } if err := parseBinds(*root, bindPath); err != nil { return err } - return nil } |