aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-01-09 21:24:50 -0500
committerDrew DeVault <sir@cmpwn.com>2018-01-09 21:31:36 -0500
commitb5d5e0dbedee34bd5d3edf13616f055d4f227d36 (patch)
treed4353b88a830a29c570b0a54adcda2126427fc95 /config
parent6394e386c2a88c3b376cd422a7b7ce5ae7534984 (diff)
Parse account configuration
Diffstat (limited to 'config')
-rw-r--r--config/config.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/config/config.go b/config/config.go
index 6a420fa..a7e9d84 100644
--- a/config/config.go
+++ b/config/config.go
@@ -4,7 +4,9 @@ import (
"github.com/go-ini/ini"
"github.com/kyoh86/xdg"
+ "fmt"
"path"
+ "strings"
"unicode"
)
@@ -47,6 +49,43 @@ func mapName(raw string) string {
return string(newstr)
}
+func loadAccountConfig(path string) ([]AccountConfig, error) {
+ var (
+ file *ini.File
+ err error
+ accounts []AccountConfig
+ )
+ accounts = make([]AccountConfig, 0)
+ if file, err = ini.Load(path); err != nil {
+ return nil, err
+ }
+ file.NameMapper = mapName
+ for _, _sec := range file.SectionStrings() {
+ if _sec == "DEFAULT" {
+ continue
+ }
+ sec := file.Section(_sec)
+ account := AccountConfig{Name: _sec}
+ if err = sec.MapTo(&account); err != nil {
+ return nil, err
+ }
+ for key, val := range sec.KeysHash() {
+ if key == "source" {
+ account.Source = val
+ } else if key == "folders" {
+ account.Folders = strings.Split(val, ",")
+ } else if key != "name" {
+ account.Params[key] = val
+ }
+ }
+ if account.Source == "" {
+ return nil, fmt.Errorf("Expected source for account %s", _sec)
+ }
+ accounts = append(accounts, account)
+ }
+ return accounts, nil
+}
+
func LoadConfig(root *string) (*AercConfig, error) {
var (
err error
@@ -80,5 +119,11 @@ func LoadConfig(root *string) (*AercConfig, error) {
if ui, err := file.GetSection("ui"); err != nil {
ui.MapTo(config.Ui)
}
+ accountsPath := path.Join(*root, "accounts.conf")
+ if accounts, err := loadAccountConfig(accountsPath); err != nil {
+ return nil, err
+ } else {
+ config.Accounts = accounts
+ }
return config, nil
}