-
Notifications
You must be signed in to change notification settings - Fork 18
/
default.go
73 lines (62 loc) · 1.81 KB
/
default.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
package parseable
import (
"github.com/cirruslabs/cirrus-cli/pkg/parser/nameable"
"github.com/lestrrat-go/jsschema"
)
type DefaultParser struct {
fields []Field
collectibleFields []CollectibleField
collectible bool
}
func (parser *DefaultParser) OptionalField(name nameable.Nameable, schema *schema.Schema, onFound nodeFunc) {
parser.fields = append(parser.fields, Field{
name: name,
onFound: onFound,
schema: schema,
})
}
func (parser *DefaultParser) OptionalRepeatableField(name nameable.Nameable, schema *schema.Schema, onFound nodeFunc) {
parser.fields = append(parser.fields, Field{
name: name,
repeatable: true,
onFound: onFound,
schema: schema,
})
}
func (parser *DefaultParser) RequiredField(nameable nameable.Nameable, schema *schema.Schema, onFound nodeFunc) {
parser.fields = append(parser.fields, Field{
name: nameable,
required: true,
onFound: onFound,
schema: schema,
})
}
func (parser *DefaultParser) CollectibleField(name string, schema *schema.Schema, onFound nodeFunc) {
parser.collectibleFields = append(parser.collectibleFields, CollectibleField{
Name: name,
onFound: onFound,
Schema: schema,
})
}
func (parser *DefaultParser) CollectibleInstanceField(name string, schema *schema.Schema, onFound nodeFunc) {
parser.collectibleFields = append(parser.collectibleFields, CollectibleField{
Name: name,
DefinesInstance: true,
onFound: onFound,
Schema: schema,
})
}
func (parser *DefaultParser) Collectible() bool {
return parser.collectible
}
func (parser *DefaultParser) SetCollectible(value bool) {
parser.collectible = value
}
func (parser *DefaultParser) FindFieldByName(name string) *Field {
for _, field := range parser.fields {
if field.name.Matches(name) {
return &field
}
}
return nil
}