-
Notifications
You must be signed in to change notification settings - Fork 3
/
value.go
44 lines (34 loc) · 845 Bytes
/
value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package flagbind
import (
"encoding"
"encoding/json"
)
type JSONRawMessage json.RawMessage
func (data *JSONRawMessage) Set(text string) error {
return json.Unmarshal([]byte(text), (*json.RawMessage)(data))
}
func (data JSONRawMessage) String() string {
return string(data)
}
func (data JSONRawMessage) Type() string { return "JSON" }
type pflagMarshalerValue struct {
marshaler textBidiMarshaler
typeStr string
}
type textBidiMarshaler interface {
encoding.TextMarshaler
encoding.TextUnmarshaler
}
func (val pflagMarshalerValue) String() string {
text, err := val.marshaler.MarshalText()
if err != nil {
return "<invalid>"
}
return string(text)
}
func (val pflagMarshalerValue) Type() string {
return val.typeStr
}
func (val *pflagMarshalerValue) Set(v string) error {
return val.marshaler.UnmarshalText([]byte(v))
}