Add check for installing golint before running it
This commit is contained in:
parent
6ec1ce9730
commit
f66760a2b5
17
magefile.go
17
magefile.go
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user