-
Notifications
You must be signed in to change notification settings - Fork 7
/
types.go
73 lines (68 loc) · 1.77 KB
/
types.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 cwl
import "strings"
// Type represents CWL Typeable objects.
// - http://www.commonwl.org/v1.0/CommandLineTool.html#CWLType
// - http://www.commonwl.org/v1.0/CommandLineTool.html#CommandInputRecordSchema
// - http://www.commonwl.org/v1.0/CommandLineTool.html#CommandInputEnumSchema
// - http://www.commonwl.org/v1.0/CommandLineTool.html#CommandInputArraySchema
type Type struct {
Type string
Label string
Binding *Binding
Fields Fields // from CommandInputRecordSchema
Symbols []string // from CommandInputEnumSchema
Items []Type // from CommandInputArraySchema
Name string
}
// NewList constructs a list of Type from any interface.
// It only handles []interface{}
func (_ Type) NewList(i interface{}) []Type {
dest := []Type{}
switch x := i.(type) {
case []interface{}:
for _, s := range x {
dest = append(dest, Type{}.New(s))
}
default:
dest = append(dest, Type{}.New(x))
}
return dest
}
// New constructs single Type struct from any interface.
func (_ Type) New(i interface{}) Type {
dest := Type{}
switch x := i.(type) {
case string:
dest.Type = x
case map[string]interface{}:
for key, v := range x {
switch key {
case "type":
dest.Type = v.(string)
case "items":
dest.Items = Type{}.NewList(v)
case "inputBinding":
dest.Binding = Binding{}.New(v)
case "fields":
dest.Fields = Fields{}.New(v)
case "symbols":
dest.Symbols = StringArrayable(v)
case "name":
dest.Name = v.(string)
}
}
}
return dest
}
// NeedRequirement ...
func (t Type) NeedRequirement() (string, bool) {
if strings.HasPrefix(t.Type, "#") {
return strings.TrimPrefix(t.Type, "#"), true
}
for _, itemtype := range t.Items {
if key, needed := itemtype.NeedRequirement(); needed {
return key, needed
}
}
return "", false
}