Skip to content

Commit

Permalink
Support parsing []string and []color.Color config values
Browse files Browse the repository at this point in the history
  • Loading branch information
zMoooooritz authored and muesli committed Jul 14, 2021
1 parent 14d2207 commit 2035051
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"reflect"
"strconv"
"strings"

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

case *[]string:
switch vt := v.(type) {
case string:
*d = strings.Split(vt, ";")
default:
return fmt.Errorf("unhandled type %+v for []string conversion", reflect.TypeOf(vt))
}

case *[]color.Color:
switch vt := v.(type) {
case string:
cls := strings.Split(vt, ";")
var clrs []color.Color
for _, cl := range cls {
clr, _ := colorful.Hex(cl)
clrs = append(clrs, clr)
}
*d = clrs
default:
return fmt.Errorf("unhandled type %+v for []color.Color conversion", reflect.TypeOf(vt))
}

default:
return fmt.Errorf("unhandled dst type %+v", reflect.TypeOf(dst))
}
Expand Down

0 comments on commit 2035051

Please sign in to comment.