-
Notifications
You must be signed in to change notification settings - Fork 103
/
option.go
74 lines (59 loc) · 1.4 KB
/
option.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package schema
import (
"fmt"
"github.com/mitchellh/hashstructure/v2"
"go.starlark.net/starlark"
)
type Option struct {
SchemaOption
}
func newOption(
thread *starlark.Thread,
_ *starlark.Builtin,
args starlark.Tuple,
kwargs []starlark.Tuple,
) (starlark.Value, error) {
var (
display starlark.String
value starlark.String
)
if err := starlark.UnpackArgs(
"Option",
args, kwargs,
"display", &display,
"value", &value,
); err != nil {
return nil, fmt.Errorf("unpacking arguments for Option: %s", err)
}
s := &Option{}
s.SchemaOption.Text = display.GoString()
s.SchemaOption.Display = display.GoString()
s.SchemaOption.Value = value.GoString()
return s, nil
}
func (s *Option) AsSchemaOption() SchemaOption {
return s.SchemaOption
}
func (s *Option) AttrNames() []string {
return []string{
"display", "value",
}
}
func (s *Option) Attr(name string) (starlark.Value, error) {
switch name {
case "display":
return starlark.String(s.Text), nil
case "value":
return starlark.String(s.Value), nil
default:
return nil, nil
}
}
func (s *Option) String() string { return "Option(...)" }
func (s *Option) Type() string { return "Option" }
func (s *Option) Freeze() {}
func (s *Option) Truth() starlark.Bool { return true }
func (s *Option) Hash() (uint32, error) {
sum, err := hashstructure.Hash(s, hashstructure.FormatV2, nil)
return uint32(sum), err
}