MCPcopy
hub / github.com/spf13/pflag / newTextValue

Function newTextValue

text.go:12–26  ·  view source on GitHub ↗
(val encoding.TextMarshaler, p encoding.TextUnmarshaler)

Source from the content-addressed store, hash-verified

10type textValue struct{ p encoding.TextUnmarshaler }
11
12func newTextValue(val encoding.TextMarshaler, p encoding.TextUnmarshaler) textValue {
13 ptrVal := reflect.ValueOf(p)
14 if ptrVal.Kind() != reflect.Ptr {
15 panic("variable value type must be a pointer")
16 }
17 defVal := reflect.ValueOf(val)
18 if defVal.Kind() == reflect.Ptr {
19 defVal = defVal.Elem()
20 }
21 if defVal.Type() != ptrVal.Type().Elem() {
22 panic(fmt.Sprintf("default type does not match variable type: %v != %v", defVal.Type(), ptrVal.Type().Elem()))
23 }
24 ptrVal.Elem().Set(defVal)
25 return textValue{p}
26}
27
28func (v textValue) Set(s string) error {
29 return v.p.UnmarshalText([]byte(s))

Callers 4

TextVarMethod · 0.85
TextVarPMethod · 0.85
TextVarFunction · 0.85
TextVarPFunction · 0.85

Calls 2

TypeMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected