-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
42 lines (36 loc) · 854 Bytes
/
main.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
package main
import (
"flag"
"io/ioutil"
"os"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/ivancorrales/hcl-by-example/dsl"
)
func main() {
var inputPath string
flag.StringVar(&inputPath, "input", "example.hcl", "path to the input file")
flag.Parse()
pipeline, err := loadInputfile(inputPath)
if err != nil {
println(err.Error())
os.Exit(1)
}
pipeline.Run()
}
func loadInputfile(path string) (*dsl.Pipeline, error) {
content, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
file, diagnostics := hclsyntax.ParseConfig(content, path,
hcl.Pos{Line: 1, Column: 1, Byte: 0})
if diagnostics != nil && diagnostics.HasErrors() {
return nil, diagnostics.Errs()[0]
}
out, decodeErr := dsl.Decode(file.Body)
if decodeErr != nil {
return nil, decodeErr
}
return out, nil
}