github.com/Azure/tflint-ruleset-azurerm-ext@v0.6.0/install/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "os/exec" 7 "runtime" 8 ) 9 10 func main() { 11 var cmds map[string]func() = map[string]func(){ 12 "install": install, 13 "clean": clean, 14 "prepare": prepare, 15 } 16 cmd := os.Args[1] 17 cmds[cmd]() 18 } 19 20 func prepare() { 21 clean() 22 goModEnsure() 23 } 24 25 func goModEnsure() { 26 if err := exec.Command("go", "mod", "tidy").Run(); err != nil { 27 panic(err.Error()) 28 } 29 if err := exec.Command("go", "mod", "vendor").Run(); err != nil { 30 panic(err.Error()) 31 } 32 } 33 34 func clean() {} 35 36 func install() { 37 outputDir := fmt.Sprintf("%s/.tflint.d/plugins", os.Getenv("HOME")) 38 if runtime.GOOS == "windows" { 39 baseDir := os.Getenv("USERPROFILE") 40 outputDir = fmt.Sprintf(`%s\.tflint.d\plugins`, baseDir) 41 } 42 if dir := os.Getenv("TFLINT_PLUGIN_DIR"); dir != "" { 43 outputDir = dir 44 } else { 45 _ = os.MkdirAll(outputDir, os.ModePerm) 46 } 47 //#nosec G204 48 cmd := exec.Command("go", "build", "-o", outputDir) 49 if err := cmd.Run(); err != nil { 50 panic(err.Error()) 51 } 52 }