-
Notifications
You must be signed in to change notification settings - Fork 2k
/
spec.go
188 lines (166 loc) · 3.86 KB
/
spec.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package hclspec
// ObjectSpec wraps the object and returns a spec.
func ObjectSpec(obj *Object) *Spec {
return &Spec{
Block: &Spec_Object{
Object: obj,
},
}
}
// ArraySpec wraps the array and returns a spec.
func ArraySpec(array *Array) *Spec {
return &Spec{
Block: &Spec_Array{
Array: array,
},
}
}
// AttrSpec wraps the attr and returns a spec.
func AttrSpec(attr *Attr) *Spec {
return &Spec{
Block: &Spec_Attr{
Attr: attr,
},
}
}
// BlockSpec wraps the block and returns a spec.
func BlockSpec(block *Block) *Spec {
return &Spec{
Block: &Spec_BlockValue{
BlockValue: block,
},
}
}
// BlockAttrsSpec wraps the block attrs and returns a spec.
func BlockAttrsSpec(blockAttrs *BlockAttrs) *Spec {
return &Spec{
Block: &Spec_BlockAttrs{
BlockAttrs: blockAttrs,
},
}
}
// BlockListSpec wraps the block list and returns a spec.
func BlockListSpec(blockList *BlockList) *Spec {
return &Spec{
Block: &Spec_BlockList{
BlockList: blockList,
},
}
}
// BlockSetSpec wraps the block set and returns a spec.
func BlockSetSpec(blockSet *BlockSet) *Spec {
return &Spec{
Block: &Spec_BlockSet{
BlockSet: blockSet,
},
}
}
// BlockMapSpec wraps the block map and returns a spec.
func BlockMapSpec(blockMap *BlockMap) *Spec {
return &Spec{
Block: &Spec_BlockMap{
BlockMap: blockMap,
},
}
}
// DefaultSpec wraps the default and returns a spec.
func DefaultSpec(d *Default) *Spec {
return &Spec{
Block: &Spec_Default{
Default: d,
},
}
}
// LiteralSpec wraps the literal and returns a spec.
func LiteralSpec(l *Literal) *Spec {
return &Spec{
Block: &Spec_Literal{
Literal: l,
},
}
}
// NewObject returns a new object spec.
func NewObject(attrs map[string]*Spec) *Spec {
return ObjectSpec(&Object{
Attributes: attrs,
})
}
// NewAttr returns a new attribute spec.
func NewAttr(name, attrType string, required bool) *Spec {
return AttrSpec(&Attr{
Name: name,
Type: attrType,
Required: required,
})
}
// NewBlock returns a new block spec.
func NewBlock(name string, required bool, nested *Spec) *Spec {
return BlockSpec(&Block{
Name: name,
Required: required,
Nested: nested,
})
}
// NewBlockAttrs returns a new block attrs spec
func NewBlockAttrs(name, elementType string, required bool) *Spec {
return BlockAttrsSpec(&BlockAttrs{
Name: name,
Required: required,
Type: elementType,
})
}
// NewBlockList returns a new block list spec that has no limits.
func NewBlockList(name string, nested *Spec) *Spec {
return NewBlockListLimited(name, 0, 0, nested)
}
// NewBlockListLimited returns a new block list spec that limits the number of
// blocks.
func NewBlockListLimited(name string, min, max uint64, nested *Spec) *Spec {
return BlockListSpec(&BlockList{
Name: name,
MinItems: min,
MaxItems: max,
Nested: nested,
})
}
// NewBlockSet returns a new block set spec that has no limits.
func NewBlockSet(name string, nested *Spec) *Spec {
return NewBlockSetLimited(name, 0, 0, nested)
}
// NewBlockSetLimited returns a new block set spec that limits the number of
// blocks.
func NewBlockSetLimited(name string, min, max uint64, nested *Spec) *Spec {
return BlockSetSpec(&BlockSet{
Name: name,
MinItems: min,
MaxItems: max,
Nested: nested,
})
}
// NewBlockMap returns a new block map spec.
func NewBlockMap(name string, labels []string, nested *Spec) *Spec {
return BlockMapSpec(&BlockMap{
Name: name,
Labels: labels,
Nested: nested,
})
}
// NewLiteral returns a new literal spec.
func NewLiteral(value string) *Spec {
return LiteralSpec(&Literal{
Value: value,
})
}
// NewDefault returns a new default spec.
func NewDefault(primary, defaultValue *Spec) *Spec {
return DefaultSpec(&Default{
Primary: primary,
Default: defaultValue,
})
}
// NewArray returns a new array spec.
func NewArray(values []*Spec) *Spec {
return ArraySpec(&Array{
Values: values,
})
}