-
Notifications
You must be signed in to change notification settings - Fork 151
/
args.go
33 lines (29 loc) · 1.06 KB
/
args.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
package instance
import (
"github.com/scaleway/scaleway-cli/v2/internal/args"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
)
func init() {
args.RegisterMarshalFunc((*instance.NullableStringValue)(nil), marshalNullableStringValue())
args.RegisterUnmarshalFunc((*instance.NullableStringValue)(nil), unmarshalNullableStringValue())
}
func marshalNullableStringValue() args.MarshalFunc {
return func(src interface{}) (s string, e error) {
nullableStringValue := src.(*instance.NullableStringValue)
return nullableStringValue.Value, nil
}
}
// unmarshalNullableStringValue unmarshal an arg into a nullableStringValue
//
// value= => instance.NullableStringValue{ Null: true, Value: "", }
// value=none => instance.NullableStringValue{ Null: true, Value: "none", }
func unmarshalNullableStringValue() args.UnmarshalFunc {
return func(value string, dest interface{}) error {
nullableStringValue := dest.(*instance.NullableStringValue)
nullableStringValue.Value = value
if value == "" || value == "none" {
nullableStringValue.Null = true
}
return nil
}
}