//go:build mage // Magefile for ior targets: build, test, install. package main import ( "fmt" "os" "path/filepath" "github.com/magefile/mage/mg" "github.com/magefile/mage/sh" ) const binaryName = "ior" // Default builds the project. func Default() { mg.Deps(Build) } // Build compiles the binary. func Build() error { return sh.RunV("go", "build", "-o", binaryName, "./cmd/ior") } // Test runs the full test suite. func Test() error { return sh.RunV("go", "test", "./...") } // Install copies the binary into GOPATH/bin. func Install() error { mg.Deps(Build) goPath := os.Getenv("GOPATH") if goPath == "" { home, err := os.UserHomeDir() if err != nil { return fmt.Errorf("resolve home directory: %w", err) } goPath = filepath.Join(home, "go") } binDir := filepath.Join(goPath, "bin") if err := os.MkdirAll(binDir, 0o755); err != nil { return fmt.Errorf("ensure %s: %w", binDir, err) } dest := filepath.Join(binDir, binaryName) return sh.RunV("cp", "-v", binaryName, dest) }