mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-28 08:27:42 +08:00
Support parsing json config with hcl v2
Signed-off-by: Patrick Van Stee <patrick@vanstee.me>
This commit is contained in:
parent
eadf5eddbc
commit
340686a383
11
bake/hcl.go
11
bake/hcl.go
@ -8,6 +8,7 @@ import (
|
||||
"github.com/hashicorp/hcl/v2/ext/userfunc"
|
||||
"github.com/hashicorp/hcl/v2/hclsimple"
|
||||
"github.com/hashicorp/hcl/v2/hclsyntax"
|
||||
"github.com/hashicorp/hcl/v2/json"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
"github.com/zclconf/go-cty/cty/function"
|
||||
"github.com/zclconf/go-cty/cty/function/stdlib"
|
||||
@ -73,8 +74,16 @@ type staticConfig struct {
|
||||
}
|
||||
|
||||
func ParseHCL(dt []byte, fn string) (*Config, error) {
|
||||
var file *hcl.File
|
||||
var diags hcl.Diagnostics
|
||||
|
||||
// Decode user defined functions.
|
||||
file, diags := hclsyntax.ParseConfig(dt, fn, hcl.Pos{Line: 1, Column: 1})
|
||||
fnl := strings.ToLower(fn)
|
||||
if strings.HasSuffix(fnl, ".json") {
|
||||
file, diags = json.Parse(dt, fn)
|
||||
} else {
|
||||
file, diags = hclsyntax.ParseConfig(dt, fn, hcl.Pos{Line: 1, Column: 1})
|
||||
}
|
||||
if diags.HasErrors() {
|
||||
return nil, diags
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user