-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
41 lines (33 loc) · 887 Bytes
/
run.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
package factory
import (
"github.com/hashicorp/hcl/v2"
)
var runBlockSchema = &hcl.BodySchema{
Attributes: []hcl.AttributeSchema{
{Name: "command"},
{Name: "file"},
},
}
type RunBlock struct {
Name string
Commands []string
File string
}
func decodeRunBlock(block *hcl.Block, file *File, stageName string) (RunBlock, hcl.Diagnostics) {
// Decode Run block
run, diags := block.Body.Content(runBlockSchema)
runBlock := RunBlock{
Name: block.Labels[0],
}
if command, ok := run.Attributes["command"]; ok {
val, d := command.Expr.Value(file.GetEvalContext(&stageName))
diags = append(diags, d...)
runBlock.Commands = append(runBlock.Commands, val.AsString())
}
if f, ok := run.Attributes["file"]; ok {
val, d := f.Expr.Value(file.GetEvalContext(&stageName))
diags = append(diags, d...)
runBlock.File = val.AsString()
}
return runBlock, diags
}