scripts/generate-plugins.go: programatically gofmt the file before outputing it to avoid having to do that later on
This commit is contained in:
parent
0a46bb9525
commit
b15c92bc1e
1
Makefile
1
Makefile
|
@ -121,7 +121,6 @@ generate: install-gen-deps ## Generate dynamically generated code
|
|||
@find post-processor common helper template builder provisioner -type f | xargs grep -l '^// Code generated' | xargs rm
|
||||
go generate ./...
|
||||
go fmt common/bootcommand/boot_command.go
|
||||
go fmt command/plugin.go
|
||||
|
||||
generate-check: generate ## Check go code generation is on par
|
||||
@echo "==> Checking that auto-generated code is not changed..."
|
||||
|
|
|
@ -15,6 +15,8 @@ import (
|
|||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/imports"
|
||||
)
|
||||
|
||||
const target = "command/plugin.go"
|
||||
|
@ -58,6 +60,8 @@ func main() {
|
|||
}
|
||||
defer file.Close()
|
||||
|
||||
output = string(goFmt(target, []byte(output)))
|
||||
|
||||
_, err = file.WriteString(output)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed writing to %s: %s", target, err)
|
||||
|
@ -66,6 +70,15 @@ func main() {
|
|||
log.Printf("Generated %s", target)
|
||||
}
|
||||
|
||||
func goFmt(filename string, b []byte) []byte {
|
||||
fb, err := imports.Process(filename, b, nil)
|
||||
if err != nil {
|
||||
log.Printf("formatting err: %v", err)
|
||||
return b
|
||||
}
|
||||
return fb
|
||||
}
|
||||
|
||||
type plugin struct {
|
||||
Package string // This plugin's package name (iso)
|
||||
PluginName string // Name of plugin (vmware-iso)
|
||||
|
|
Loading…
Reference in New Issue