nurse/magefiles/tools.go
Peter Kurfer 9791e9f282
All checks were successful
Renovate / renovate (push) Successful in 40s
Go build / build (push) Successful in 8m44s
feat: refactor to server and exec-check subcommands
- allow to interactively execute checks instead of server mode
- use urfave/cli for subcommands
2023-12-04 11:22:49 +01:00

32 lines
740 B
Go

package main
import (
"fmt"
"log/slog"
"os/exec"
"github.com/magefile/mage/sh"
)
var (
GoReleaser = sh.RunCmd("goreleaser")
GoInstall = sh.RunCmd("go", "install")
GoBuild = sh.RunCmd("go", "build")
)
func ensureGoTool(toolName, importPath, version string) error {
return checkForTool(toolName, func() error {
toolToInstall := fmt.Sprintf("%s@%s", importPath, version)
slog.Info("Installing Go tool", slog.String("toolToInstall", toolToInstall))
return GoInstall(toolToInstall)
})
}
func checkForTool(toolName string, fallbackAction func() error) error {
if _, err := exec.LookPath(toolName); err != nil {
slog.Warn("tool is missing", slog.String("toolName", toolName))
return fallbackAction()
}
return nil
}