/
output.go
59 lines (47 loc) · 1.33 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
package cfg
// Output is the tasks output section
type Output struct {
DockerImage []DockerImageOutput
File []FileOutput
}
func (out *Output) DockerImageOutputs() []DockerImageOutput {
return out.DockerImage
}
func (out *Output) FileOutputs() []FileOutput {
return out.File
}
func (out *Output) Resolve(resolver Resolver) error {
for i, dockerImage := range out.DockerImage {
if err := dockerImage.resolve(resolver); err != nil {
return fieldErrorWrap(err, "DockerImage")
}
// replace the slice element because dockerImage is a copy
out.DockerImage[i] = dockerImage
}
for i, file := range out.File {
if err := file.resolve(resolver); err != nil {
return fieldErrorWrap(err, "FileOutput")
}
// replace the slice element because file is a copy
out.File[i] = file
}
return nil
}
// Merge appends the information in other to out.
func (out *Output) Merge(other OutputDef) {
out.DockerImage = append(out.DockerImage, other.DockerImageOutputs()...)
out.File = append(out.File, other.FileOutputs()...)
}
func outputValidate(o OutputDef) error {
for _, f := range o.FileOutputs() {
if err := f.validate(); err != nil {
return fieldErrorWrap(err, "File")
}
}
for _, d := range o.DockerImageOutputs() {
if err := d.validate(); err != nil {
return fieldErrorWrap(err, "DockerImage")
}
}
return nil
}