github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/plugin/stub-generator/main.go (about)

     1  package main
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"os"
     7  	"os/exec"
     8  	"path/filepath"
     9  	"runtime"
    10  )
    11  
    12  func main() {
    13  	_, file, _, _ := runtime.Caller(0)
    14  	dir := filepath.Dir(file)
    15  
    16  	if err := os.Chdir(dir); err != nil {
    17  		panic(err)
    18  	}
    19  
    20  	execCommand("go", "build", "-o", "../test-fixtures/plugins/tflint-ruleset-foo"+fileExt(), "./sources/foo/main.go")
    21  	execCommand("cp", "../test-fixtures/plugins/tflint-ruleset-foo"+fileExt(), "../test-fixtures/locals/.tflint.d/plugins/tflint-ruleset-foo"+fileExt())
    22  	execCommand("go", "build", "-o", "../test-fixtures/plugins/tflint-ruleset-bar"+fileExt(), "./sources/bar/main.go")
    23  	execCommand("go", "build", "-o", "../../integration/plugin/.tflint.d/plugins/tflint-ruleset-example"+fileExt(), "./sources/example/main.go")
    24  }
    25  
    26  func fileExt() string {
    27  	if runtime.GOOS == "windows" {
    28  		return ".exe"
    29  	}
    30  	return ""
    31  }
    32  
    33  func execCommand(command string, args ...string) {
    34  	cmd := exec.Command(command, args...)
    35  	var stderr bytes.Buffer
    36  	cmd.Stderr = &stderr
    37  
    38  	if err := cmd.Run(); err != nil {
    39  		panic(fmt.Sprintf("Failed to exec command: %s", stderr.String()))
    40  	}
    41  }