-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathworkflow_handlers.go
142 lines (122 loc) · 2.71 KB
/
workflow_handlers.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
package cwl
import (
"fmt"
"github.com/commondream/yamlast"
)
func (l *loader) MappingToWorkflowInputSlice(n node) ([]WorkflowInput, error) {
var inputs []WorkflowInput
for _, kv := range itermap(n) {
k := kv.k
v := kv.v
i := WorkflowInput{ID: k}
switch v.Kind {
case yamlast.MappingNode:
err := l.load(v, &i)
if err != nil {
return nil, err
}
i.ID = k
case yamlast.ScalarNode:
err := l.load(v, &i.Type)
if err != nil {
return nil, err
}
default:
// TODO want errors to return position information
return nil, fmt.Errorf("invalid yaml node type for workflow input")
}
inputs = append(inputs, i)
}
return inputs, nil
}
func (l *loader) MappingToWorkflowOutputSlice(n node) ([]WorkflowOutput, error) {
var outputs []WorkflowOutput
for _, kv := range itermap(n) {
k := kv.k
v := kv.v
o := WorkflowOutput{ID: k}
switch v.Kind {
case yamlast.MappingNode:
err := l.load(v, &o)
if err != nil {
return nil, err
}
o.ID = k
case yamlast.ScalarNode:
err := l.load(v, &o.Type)
if err != nil {
return nil, err
}
default:
// TODO want errors to return position information
return nil, fmt.Errorf("invalid yaml node type for workflow output")
}
outputs = append(outputs, o)
}
return outputs, nil
}
func (l *loader) MappingToStepSlice(n node) ([]Step, error) {
steps := []Step{}
for _, kv := range itermap(n) {
k := kv.k
v := kv.v
step := Step{}
err := l.load(v, &step)
if err != nil {
return nil, err
}
step.ID = k
steps = append(steps, step)
}
return steps, nil
}
func (l *loader) ScalarToStepOutput(n node) (StepOutput, error) {
return StepOutput{ID: n.Value}, nil
}
func (l *loader) SeqToStepInputSlice(n node) ([]StepInput, error) {
ins := []StepInput{}
for _, c := range n.Children {
in := StepInput{}
err := l.load(c, &in)
if err != nil {
return nil, err
}
ins = append(ins, in)
}
return ins, nil
}
func (l *loader) SeqToStepOutputSlice(n node) ([]StepOutput, error) {
outs := []StepOutput{}
for _, c := range n.Children {
out := StepOutput{}
err := l.load(c, &out)
if err != nil {
return nil, err
}
outs = append(outs, out)
}
return outs, nil
}
func (l *loader) MappingToStepInputSlice(n node) ([]StepInput, error) {
ins := []StepInput{}
for _, kv := range itermap(n) {
k := kv.k
v := kv.v
in := StepInput{ID: k}
switch v.Kind {
case yamlast.MappingNode:
err := l.load(v, &in)
if err != nil {
return nil, err
}
in.ID = k
case yamlast.ScalarNode:
in.Source = []string{v.Value}
default:
// TODO want errors to return position information
return nil, fmt.Errorf("invalid yaml node type for step input")
}
ins = append(ins, in)
}
return ins, nil
}