-
Notifications
You must be signed in to change notification settings - Fork 7
/
step.go
88 lines (80 loc) · 1.81 KB
/
step.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
package cwl
// Steps represents "steps" field in CWL.
type Steps []Step
// New constructs "Steps" from interface.
func (_ Steps) New(i interface{}) Steps {
dest := Steps{}
switch x := i.(type) {
case []interface{}:
for _, v := range x {
s := Step{}.New(v)
dest = append(dest, s)
}
case map[string]interface{}:
for key, v := range x {
s := Step{}.New(v)
s.ID = key
dest = append(dest, s)
}
}
return dest
}
// Step represents WorkflowStep.
// @see http://www.commonwl.org/v1.0/Workflow.html#WorkflowStep
type Step struct {
ID string
In StepInputs
Out []StepOutput
Run Run
Requirements []Requirement
Scatter []string
ScatterMethod string
}
// Run `run` accept string | CommandLineTool | ExpressionTool | Workflow
type Run struct {
Value string
Workflow *Root
}
// New constructs "Step" from interface.
func (_ Step) New(i interface{}) Step {
dest := Step{}
switch x := i.(type) {
case map[string]interface{}:
for key, v := range x {
switch key {
case "id":
dest.ID = v.(string)
case "run":
switch x2 := v.(type) {
case string:
dest.Run.Value = x2
case map[string]interface{}:
dest.Run.Workflow = dest.Run.Workflow.AsStep(v)
}
case "in":
dest.In = StepInput{}.NewList(v)
case "out":
dest.Out = StepOutput{}.NewList(v)
case "requirements":
dest.Requirements = Requirements{}.New(v)
case "scatter":
dest.Scatter = StringArrayable(v)
case "scatterMethod":
dest.ScatterMethod = v.(string)
}
}
}
return dest
}
// Len for sorting
func (steps Steps) Len() int {
return len(steps)
}
// Less for sorting
func (steps Steps) Less(i, j int) bool {
return steps[i].ID < steps[j].ID
}
// Swap for sorting
func (steps Steps) Swap(i, j int) {
steps[i], steps[j] = steps[j], steps[i]
}