-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaccessors.go
173 lines (155 loc) · 3.83 KB
/
accessors.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
package cwl
import (
"strings"
)
func (t *Tool) RequiresDocker() (*DockerRequirement, bool) {
reqs := append([]Requirement{}, t.Requirements...)
reqs = append(reqs, t.Hints...)
for _, req := range reqs {
if r, ok := req.(DockerRequirement); ok {
return &r, true
}
}
return nil, false
}
func (t *Tool) RequiresShellCommand() bool {
reqs := append([]Requirement{}, t.Requirements...)
reqs = append(reqs, t.Hints...)
for _, req := range reqs {
if _, ok := req.(ShellCommandRequirement); ok {
return true
}
}
return false
}
func (t *Tool) RequiresInlineJavascript() ([]string, bool) {
reqs := append([]Requirement{}, t.Requirements...)
reqs = append(reqs, t.Hints...)
for _, req := range reqs {
if r, ok := req.(InlineJavascriptRequirement); ok {
return r.ExpressionLib, true
}
}
return nil, false
}
func (t *Tool) RequiresSchemaDef() (*SchemaDefRequirement, bool) {
reqs := append([]Requirement{}, t.Requirements...)
reqs = append(reqs, t.Hints...)
for _, req := range reqs {
if r, ok := req.(SchemaDefRequirement); ok {
return &r, true
}
}
return nil, false
}
func (t *Tool) ResolveSchemaDefs() error {
defs, required := t.RequiresSchemaDef()
if !required {
return nil
}
byName := map[string]SchemaDef{}
for _, def := range defs.Types {
byName[def.Name] = def
}
for _, in := range t.Inputs {
for i, r := range in.Type {
t, err := resolveSchemaDef(byName, r)
if err != nil {
return err
}
inputType, ok := t.(InputType)
if !ok {
return errf("input type schema reference resolved to non-input type")
}
in.Type[i] = inputType
}
}
return nil
}
// resolveSchemaDef recursively resolves references to SchemaDefRequirement types
// by name. Note that schemas defined in the requirement may themselves refer
// to schemas by name. If no type mapping is done, resolveSchemaDef returns the
// original type.
func resolveSchemaDef(byName map[string]SchemaDef, in interface{}) (interface{}, error) {
switch z := in.(type) {
case TypeRef:
name := strings.TrimPrefix(z.Name, "#")
def, found := byName[name]
if !found {
return nil, errf(`no schema def named "%s"`, z.Name)
}
// A schema type defined in a SchemaDefRequirement may itself refer
// to other types by name, so recursively resolve this type.
//
// TODO there is a chance of infinite recursion here if types
// have a circular reference. Would be nice to catch this with
// a good error message.
t, err := resolveSchemaDef(byName, def.Type.(cwltype))
if err != nil {
return nil, err
}
return t, nil
case InputField:
for i, f := range z.Type {
t, err := resolveSchemaDef(byName, f)
if err != nil {
return nil, err
}
inputType, ok := t.(InputType)
if !ok {
return nil, errf("input type schema reference resolved to non-input type")
}
z.Type[i] = inputType
}
case InputRecord:
for _, f := range z.Fields {
_, err := resolveSchemaDef(byName, f)
if err != nil {
return nil, err
}
}
case InputArray:
for i, f := range z.Items {
t, err := resolveSchemaDef(byName, f)
if err != nil {
return nil, err
}
inputType, ok := t.(InputType)
if !ok {
return nil, errf("input type schema reference resolved to non-input type")
}
z.Items[i] = inputType
}
}
return in, nil
}
func (clb *CommandLineBinding) GetLoadContents() bool {
if clb == nil {
return false
}
return clb.LoadContents
}
func (clb *CommandLineBinding) GetPosition() int {
if clb == nil {
return 0
}
return clb.Position
}
func (clb *CommandLineBinding) GetPrefix() string {
if clb == nil {
return ""
}
return clb.Prefix
}
func (clb *CommandLineBinding) GetItemSeparator() string {
if clb == nil {
return ""
}
return clb.ItemSeparator
}
func (clb *CommandLineBinding) GetValueFrom() Expression {
if clb == nil {
return Expression("")
}
return clb.ValueFrom
}