generated from getporter/skeletor
/
action.go
106 lines (85 loc) · 2.42 KB
/
action.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
package functions
import (
"get.porter.sh/porter/pkg/exec/builder"
)
var _ builder.ExecutableAction = Action{}
type Action struct {
Steps []Steps // using UnmarshalYAML so that we don't need a custom type per action
}
// UnmarshalYAML takes any yaml in this form
// ACTION:
// - functions: ...
// and puts the steps into the Action.Steps field
func (a *Action) UnmarshalYAML(unmarshal func(interface{}) error) error {
var steps []Steps
results, err := builder.UnmarshalAction(unmarshal, &steps)
if err != nil {
return err
}
// Go doesn't have generics, nothing to see here...
for _, result := range results {
step := result.(*[]Steps)
a.Steps = append(a.Steps, *step...)
}
return nil
}
func (a Action) GetSteps() []builder.ExecutableStep {
// Go doesn't have generics, nothing to see here...
steps := make([]builder.ExecutableStep, len(a.Steps))
for i := range a.Steps {
steps[i] = a.Steps[i]
}
return steps
}
type Steps struct {
Step `yaml:"functions"`
}
var _ builder.ExecutableStep = Step{}
var _ builder.StepWithOutputs = Step{}
type Step struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Arguments []string `yaml:"arguments,omitempty"`
Flags builder.Flags `yaml:"flags,omitempty"`
Outputs []Output `yaml:"outputs,omitempty"`
}
func (s Step) GetCommand() string {
return "func"
}
func (s Step) GetArguments() []string {
return s.Arguments
}
func (s Step) GetFlags() builder.Flags {
return s.Flags
}
func (s Step) GetOutputs() []builder.Output {
// Go doesn't have generics, nothing to see here...
outputs := make([]builder.Output, len(s.Outputs))
for i := range s.Outputs {
outputs[i] = s.Outputs[i]
}
return outputs
}
var _ builder.OutputJsonPath = Output{}
var _ builder.OutputFile = Output{}
var _ builder.OutputRegex = Output{}
type Output struct {
Name string `yaml:"name"`
// See https://porter.sh/mixins/exec/#outputs
// TODO: If your mixin doesn't support these output types, you can remove these and the interface assertions above, and from #/definitions/outputs in schema.json
JsonPath string `yaml:"jsonPath,omitempty"`
FilePath string `yaml:"path,omitempty"`
Regex string `yaml:"regex,omitempty"`
}
func (o Output) GetName() string {
return o.Name
}
func (o Output) GetJsonPath() string {
return o.JsonPath
}
func (o Output) GetFilePath() string {
return o.FilePath
}
func (o Output) GetRegex() string {
return o.Regex
}