// SPDX-License-Identifier: MIT // Copyright (c) 2026 Paul Buetow //go:build mage package main import ( "fmt" "os" "path/filepath" "github.com/magefile/mage/sh" ) // Project description for build output const binaryName = "gt" // Default is the default target when no target is specified. var Default = Build // Build builds the gt binary. func Build() error { fmt.Println("Building gt...") return sh.RunV("go", "build", "-o", binaryName, "./cmd/gt") } // Run runs the gt binary. func Run() error { return sh.RunV("go", "run", "./cmd/gt") } // Test runs all tests. func Test() error { fmt.Println("Running all tests...") return sh.RunV("go", "test", "./...") } // TestRPN runs tests for the RPN package. func TestRPN() error { fmt.Println("Running RPN tests...") return sh.RunV("go", "test", "./internal/rpn/...") } // RPN runs tests for the RPN package (alias for TestRPN). func RPN() error { return TestRPN() } // Install installs the gt binary to GOBIN (or GOPATH/bin if GOBIN is not set). func Install() error { fmt.Println("Installing gt...") return sh.RunV("go", "install", "./cmd/gt") } // Lint runs golangci-lint for code quality checks. func Lint() error { fmt.Println("Running golangci-lint...") return sh.RunV("golangci-lint", "run", "./...") } // Release builds and packages the release for all platforms. func Release() error { fmt.Println("Creating release...") fmt.Println("Note: Requires goreleaser to be installed and configured.") return sh.RunV("goreleaser", "release", "--clean") } // Repl starts the REPL mode. func Repl() error { return sh.RunV("go", "run", "./cmd/gt", "--repl") } // Uninstall removes the gt binary from GOBIN (or GOPATH/bin if GOBIN is not set). func Uninstall() error { fmt.Println("Uninstalling gt...") // Use the same logic as go install to determine the binary location // go install installs to GOBIN or GOPATH/bin (GOBIN takes precedence) gobin := os.Getenv("GOBIN") if gobin == "" { gobin = filepath.Join(getGOPATH(), "bin") } binPath := filepath.Join(gobin, binaryName) return os.Remove(binPath) } // getGOPATH returns the GOPATH environment variable. func getGOPATH() string { gopath := os.Getenv("GOPATH") if gopath == "" { gopath = filepath.Join(os.Getenv("HOME"), "go") } return gopath }