forked from otiai10/cwl.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.go
91 lines (84 loc) · 2.17 KB
/
output.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
package cwl
// Output represents and conbines "CommandOutputParameter" and "WorkflowOutputParameter"
// @see
// - http://www.commonwl.org/v1.0/CommandLineTool.html#CommandOutputParameter
// - http://www.commonwl.org/v1.0/Workflow.html#WorkflowOutputParameter
type Output struct {
ID string `json:"id"`
Label string `json:"label"`
Doc []string `json:"doc"`
Format string `json:"format"`
Binding *Binding `json:"outputBinding"`
Source []string `json:"outputSource"`
Types []Type `json:"type"`
SecondaryFiles []SecondaryFile
}
// New constructs "Output" struct from interface.
func (_ Output) New(i interface{}) Output {
dest := Output{}
switch x := i.(type) {
case map[string]interface{}:
for key, v := range x {
switch key {
case "id":
dest.ID = v.(string)
case "type":
dest.Types = Type{}.NewList(v)
case "outputBinding":
dest.Binding = Binding{}.New(v)
case "outputSource":
dest.Source = StringArrayable(v)
case "doc":
dest.Doc = StringArrayable(v)
case "format":
dest.Format = v.(string)
case "secondaryFiles":
dest.SecondaryFiles = SecondaryFile{}.NewList(v)
}
}
case string:
dest.Types = Type{}.NewList(x)
}
return dest
}
// Outputs represents "outputs" field in "CWL".
type Outputs []Output
// New constructs "Outputs" struct.
func (_ Outputs) New(i interface{}) Outputs {
dest := Outputs{}
switch x := i.(type) {
case []interface{}:
for _, v := range x {
dest = append(dest, Output{}.New(v))
}
case map[string]interface{}:
for key, v := range x {
output := Output{}.New(v)
output.ID = key
dest = append(dest, output)
}
}
return dest
}
// Len for sorting
func (o Outputs) Len() int {
return len(o)
}
// Less for sorting
func (o Outputs) Less(i, j int) bool {
prev, next := o[i].Binding, o[j].Binding
switch [2]bool{prev == nil, next == nil} {
case [2]bool{true, true}:
return false
case [2]bool{false, true}:
return prev.Position < 0
case [2]bool{true, false}:
return next.Position > 0
default:
return prev.Position <= next.Position
}
}
// Swap for sorting
func (o Outputs) Swap(i, j int) {
o[i], o[j] = o[j], o[i]
}