Add check for installing golint before running it

This commit is contained in:
kolaente 2020-09-01 17:42:53 +02:00
parent 6ec1ce9730
commit f66760a2b5
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 16 additions and 1 deletions

View File

@ -173,6 +173,19 @@ func runAndStreamOutput(cmd string, args ...string) {
}
}
// Will check if the tool exists and if not install it from the provided import path
// If any errors occur, it will exit with a status code of 1.
func checkAndInstallGoTool(tool, importPath string) {
if err := exec.Command(tool).Run(); err != nil {
fmt.Printf("%s not installed, installing %s...\n", tool, importPath)
if err := exec.Command("go", "install", Goflags[0], importPath).Run(); err != nil {
fmt.Printf("Error installing %s\n", tool)
os.Exit(1)
}
fmt.Println("Installed.")
}
}
// Cleans all build, executable and bindata files.
func Clean() error {
if err := exec.Command("go", "clean", "./...").Run(); err != nil {
@ -235,7 +248,9 @@ func FmtCheck() error {
}
func Lint() {
checkAndInstallGoTool("golint", "golang.org/x/lint/golint")
args := append([]string{"-set_exit_status"}, ApiPackages...)
runAndStreamOutput("golint", args...)
}
// Generates static content into the final binary