diff options
| author | Alex Flint <[email protected]> | 2021-04-19 12:10:53 -0700 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2021-04-19 12:10:53 -0700 |
| commit | 1dfefdc43e8a9a06b532b5c29f876eb38f86a928 (patch) | |
| tree | 9d1be86c6864268c976ecc360fcc2015bbbbe424 /parse.go | |
| parent | f4eb7f3a585abd65b0568428b2b9fde8cebffb6a (diff) | |
factor setSlice into its own file, add setMap, and add tests for both
Diffstat (limited to 'parse.go')
| -rw-r--r-- | parse.go | 31 |
1 files changed, 0 insertions, 31 deletions
@@ -702,37 +702,6 @@ func (p *Parser) val(dest path) reflect.Value { return v } -// parse a value as the appropriate type and store it in the struct -func setSlice(dest reflect.Value, values []string, trunc bool) error { - if !dest.CanSet() { - return fmt.Errorf("field is not writable") - } - - var ptr bool - elem := dest.Type().Elem() - if elem.Kind() == reflect.Ptr && !elem.Implements(textUnmarshalerType) { - ptr = true - elem = elem.Elem() - } - - // Truncate the dest slice in case default values exist - if trunc && !dest.IsNil() { - dest.SetLen(0) - } - - for _, s := range values { - v := reflect.New(elem) - if err := scalar.ParseValue(v.Elem(), s); err != nil { - return err - } - if !ptr { - v = v.Elem() - } - dest.Set(reflect.Append(dest, v)) - } - return nil -} - // findOption finds an option from its name, or returns null if no spec is found func findOption(specs []*spec, name string) *spec { for _, spec := range specs { |
