summaryrefslogtreecommitdiff
path: root/Magefile.go
diff options
context:
space:
mode:
Diffstat (limited to 'Magefile.go')
-rw-r--r--Magefile.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/Magefile.go b/Magefile.go
new file mode 100644
index 0000000..b4ec4e7
--- /dev/null
+++ b/Magefile.go
@@ -0,0 +1,65 @@
+//go:build mage
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "path/filepath"
+)
+
+var (
+ binName = "gonf"
+ mod = "codeberg.org/snonux/gonf"
+)
+
+func run(cmd string, args ...string) error {
+ c := exec.Command(cmd, args...)
+ c.Stdout = os.Stdout
+ c.Stderr = os.Stderr
+ return c.Run()
+}
+
+// Build compiles the binary.
+func Build() error {
+ fmt.Println("building...")
+ return run("go", "build", "-o", binName, "./cmd/gonf")
+}
+
+// Test runs all unit tests.
+func Test() error {
+ fmt.Println("testing...")
+ return run("go", "test", "./...")
+}
+
+// Lint runs go vet.
+func Lint() error {
+ fmt.Println("linting...")
+ return run("go", "vet", "./...")
+}
+
+// Install builds and installs the binary to $GOPATH/bin.
+func Install() error {
+ fmt.Println("installing...")
+ return run("go", "install", "./cmd/gonf")
+}
+
+// Uninstall removes the binary from $GOPATH/bin.
+func Uninstall() error {
+ fmt.Println("uninstalling...")
+ gopath := os.Getenv("GOPATH")
+ if gopath == "" {
+ gopath = filepath.Join(os.Getenv("HOME"), "go")
+ }
+ binPath := filepath.Join(gopath, "bin", binName)
+ if err := os.Remove(binPath); err != nil {
+ if !os.IsNotExist(err) {
+ return fmt.Errorf("remove %s: %w", binPath, err)
+ }
+ fmt.Println("binary not found, nothing to remove")
+ } else {
+ fmt.Println("removed " + binPath)
+ }
+ return nil
+} \ No newline at end of file