package main import ( "flag" "fmt" "io/ioutil" "log" "antoine-roux.ml/projects/go/dijkstra/internal" "github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2/gohcl" "github.com/hashicorp/hcl/v2/hclsyntax" ) func main() { filename := flag.String("i", "-", "Input file use to generate graph") flag.Parse() src, err := ioutil.ReadFile(*filename) if err != nil { log.Fatalln(err) } file, diags := hclsyntax.ParseConfig(src, *filename, hcl.Pos{Line: 1, Column: 1}) if diags.HasErrors() { log.Fatalf("config parse: %s", fmt.Errorf("%w", diags)) } graph := &internal.Graph{} diags = gohcl.DecodeBody(file.Body, nil, graph) if diags.HasErrors() { log.Fatalf("config parse: %s", fmt.Errorf("%w", diags)) } fmt.Printf("%#v\n", *graph) for _, p := range graph.Nodes { fmt.Printf("%+v\n", p) } }