aboutsummaryrefslogtreecommitdiffstats
path: root/config/config.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-02-21 16:18:54 +0100
committerRobin Jarry <robin@jarry.cc>2023-03-02 23:56:13 +0100
commitb63c93563c622e70cda7006c1816dc6b59e75844 (patch)
tree821bd7636cf676640e7b391d8ce015bb33f2843e /config/config.go
parentd9a8edd8e9269aa1189d55c8d13caa05084435f5 (diff)
downloadaerc-b63c93563c622e70cda7006c1816dc6b59e75844.tar.gz
config: use reflection to map ini keys to struct fields
The default ini.Section.MapTo() function only handles basic types. Implement a more complete mapping solution that allows: * parsing templates, regexps, email addresses * defining a custom parsing method via the `parse:"MethodName"` tag * defining default values via the `default:"value"` tag * parsing rune values with the `type:"rune"` tag The field name must be specified in the `ini:"field-name"` tag as it was before. It is no longer optional. The `delim:"<separator>"` tag remains but can only be used to parse string arrays. It is now possible to override default values with "zero" values. For example: [ui] dirlist-delay = 0 Will override the default "200ms" value. Also: [statusline] status-columns = Will override the default "left<*,center>=,right>*" value. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go17
1 files changed, 0 insertions, 17 deletions
diff --git a/config/config.go b/config/config.go
index 6bf767af..de8cd0d0 100644
--- a/config/config.go
+++ b/config/config.go
@@ -7,28 +7,12 @@ import (
"os"
"path"
"strings"
- "unicode"
"github.com/go-ini/ini"
"github.com/kyoh86/xdg"
"github.com/mitchellh/go-homedir"
)
-// Input: TimestampFormat
-// Output: timestamp-format
-func mapName(raw string) string {
- newstr := make([]rune, 0, len(raw))
- for i, chr := range raw {
- if isUpper := 'A' <= chr && chr <= 'Z'; isUpper {
- if i > 0 {
- newstr = append(newstr, '-')
- }
- }
- newstr = append(newstr, unicode.ToLower(chr))
- }
- return string(newstr)
-}
-
// Set at build time
var (
shareDir string
@@ -126,7 +110,6 @@ func LoadConfigFromFile(root *string, accts []string) error {
if err != nil {
return err
}
- file.NameMapper = mapName
if err := parseGeneral(file); err != nil {
return err