-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli_handlers.go
135 lines (114 loc) · 2.9 KB
/
cli_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
package cwl
import (
"fmt"
"regexp"
)
// YAML allows all these values for booleans
// ...because the world needed more than true/false?
var yamlTrueRX = regexp.MustCompile(`y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON`)
var yamlFalseRX = regexp.MustCompile(`n|N|no|No|NO|false|False|FALSE|off|Off|OFF`)
func (l *loader) ScalarToCommandOutput(n node) (CommandOutput, error) {
o := CommandOutput{}
err := l.load(n, &o.Type)
return o, err
}
func (l *loader) ScalarToCommandInput(n node) (CommandInput, error) {
o := CommandInput{}
err := l.load(n, &o.Type)
return o, err
}
func (l *loader) ScalarToCommandLineBinding(n node) (CommandLineBinding, error) {
return CommandLineBinding{
ValueFrom: Expression(n.Value),
}, nil
}
func (l *loader) ScalarToBool(n node) (bool, error) {
if yamlTrueRX.MatchString(n.Value) {
return true, nil
}
if yamlFalseRX.MatchString(n.Value) {
return false, nil
}
return false, fmt.Errorf("invalid boolean value: %s", n.Value)
}
func (l *loader) ScalarToOptOut(n node) (OptOut, error) {
if yamlTrueRX.MatchString(n.Value) {
return OptOut{v: true, set: true}, nil
}
if yamlFalseRX.MatchString(n.Value) {
return OptOut{v: false, set: true}, nil
}
return OptOut{}, fmt.Errorf("invalid boolean value: %s", n.Value)
}
func (l *loader) MappingToCommandLineBindingPtr(n node) (*CommandLineBinding, error) {
clb := CommandLineBinding{}
err := l.load(n, &clb)
if err != nil {
return nil, err
}
return &clb, nil
}
func (l *loader) SeqToCommandLineBindingPtrSlice(n node) ([]*CommandLineBinding, error) {
var clbs []*CommandLineBinding
for _, c := range n.Children {
clb := CommandLineBinding{}
err := l.load(c, &clb)
if err != nil {
return nil, err
}
clbs = append(clbs, &clb)
}
return clbs, nil
}
func (l *loader) SeqToCommandInputSlice(n node) ([]CommandInput, error) {
var inputs []CommandInput
for _, c := range n.Children {
i := CommandInput{}
err := l.load(c, &i)
if err != nil {
return nil, err
}
inputs = append(inputs, i)
}
return inputs, nil
}
func (l *loader) SeqToCommandOutputSlice(n node) ([]CommandOutput, error) {
var outputs []CommandOutput
for _, c := range n.Children {
i := CommandOutput{}
err := l.load(c, &i)
if err != nil {
return nil, err
}
outputs = append(outputs, i)
}
return outputs, nil
}
func (l *loader) MappingToCommandInputSlice(n node) ([]CommandInput, error) {
var inputs []CommandInput
for _, kv := range itermap(n) {
k := kv.k
v := kv.v
i := CommandInput{}
if err := l.load(v, &i); err != nil {
return nil, err
}
i.ID = k
inputs = append(inputs, i)
}
return inputs, nil
}
func (l *loader) MappingToCommandOutputSlice(n node) ([]CommandOutput, error) {
var outputs []CommandOutput
for _, kv := range itermap(n) {
k := kv.k
v := kv.v
o := CommandOutput{}
if err := l.load(v, &o); err != nil {
return nil, err
}
o.ID = k
outputs = append(outputs, o)
}
return outputs, nil
}