Skip to content

Commit 2035051

Browse files
zMoooooritzmuesli
authored andcommitted
Support parsing []string and []color.Color config values
1 parent 14d2207 commit 2035051

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

config.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io/ioutil"
88
"reflect"
99
"strconv"
10+
"strings"
1011

1112
"github.com/BurntSushi/toml"
1213
colorful "github.com/lucasb-eyer/go-colorful"
@@ -136,6 +137,28 @@ func ConfigValue(v interface{}, dst interface{}) error {
136137
return fmt.Errorf("unhandled type %+v for color.Color conversion", reflect.TypeOf(vt))
137138
}
138139

140+
case *[]string:
141+
switch vt := v.(type) {
142+
case string:
143+
*d = strings.Split(vt, ";")
144+
default:
145+
return fmt.Errorf("unhandled type %+v for []string conversion", reflect.TypeOf(vt))
146+
}
147+
148+
case *[]color.Color:
149+
switch vt := v.(type) {
150+
case string:
151+
cls := strings.Split(vt, ";")
152+
var clrs []color.Color
153+
for _, cl := range cls {
154+
clr, _ := colorful.Hex(cl)
155+
clrs = append(clrs, clr)
156+
}
157+
*d = clrs
158+
default:
159+
return fmt.Errorf("unhandled type %+v for []color.Color conversion", reflect.TypeOf(vt))
160+
}
161+
139162
default:
140163
return fmt.Errorf("unhandled dst type %+v", reflect.TypeOf(dst))
141164
}

0 commit comments

Comments
 (0)