Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/definitions: Don't need to store definitions to bindata #476

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions cmd/definitions/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/definitions/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/Xuanwo/templateutils"
)

//go:generate go run github.com/kevinburke/go-bindata/go-bindata -nometadata -ignore "\\.go$" -prefix "../../" ./tmpl ../../definitions
//go:generate go run github.com/kevinburke/go-bindata/go-bindata -nometadata -ignore "\\.go$" -prefix "../../" ./tmpl

var (
infoT = newTmpl("cmd/definitions/tmpl/info")
Expand Down
7 changes: 1 addition & 6 deletions cmd/definitions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package main

import (
"io/ioutil"
"log"
"os"
)
Expand Down Expand Up @@ -34,12 +33,8 @@ func actionGlobal() {
func actionService(filePath string) {
data := parse()

content, err := ioutil.ReadFile(filePath)
if err != nil {
log.Fatalf("parse: %v", err)
}
srv := &ServiceSpec{}
err = parseHCL(content, filePath, srv)
err := parseHCL(filePath, srv)
if err != nil {
log.Fatalf("parse: %v", err)
}
Expand Down
14 changes: 10 additions & 4 deletions cmd/definitions/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ const (
func parse() (data *Data) {
// Parse pairs
pairSpec := &PairsSpec{}
err := parseHCL(MustAsset(pairPath), pairPath, pairSpec)
err := parseHCL(pairPath, pairSpec)
if err != nil {
log.Fatalf("parse: %v", err)
}

// Parse metadata
metaSpec := &InfosSpec{}
err = parseHCL(MustAsset(infoPath), infoPath, metaSpec)
err = parseHCL(infoPath, metaSpec)
if err != nil {
log.Fatalf("parse: %v", err)
}

// Parse operations
operationsSpec := &OperationsSpec{}
err = parseHCL(MustAsset(operationPath), operationPath, operationsSpec)
err = parseHCL(operationPath, operationsSpec)
if err != nil {
log.Fatalf("parse: %v", err)
}
Expand All @@ -46,14 +46,20 @@ func parse() (data *Data) {
return data
}

func parseHCL(src []byte, filename string, in interface{}) (err error) {
func parseHCL(filename string, in interface{}) (err error) {
var diags hcl.Diagnostics
defer func() {
if err != nil {
err = fmt.Errorf("parse hcl: %w", err)
}
}()

src, err := ioutil.ReadFile(filename)
if err != nil {
log.Printf("read file %s: %v", filename, err)
return err
}

file, diags := hclsyntax.ParseConfig(src, filename, hcl.Pos{Line: 1, Column: 1})
if diags.HasErrors() {
return diags
Expand Down