summaryrefslogtreecommitdiff
path: root/Magefile.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-20 21:06:35 +0200
committerPaul Buetow <paul@buetow.org>2026-02-20 21:06:35 +0200
commit59e86c9fd39308bc6b632e02ecf4d37265dabc91 (patch)
tree20e865fa680df4cff10056fa238ad07d7c58f458 /Magefile.go
parent0441f47fd585812b9c1f98b8a3dbeee03aa70b03 (diff)
Add Go implementation (goprecords)v0.1.0
- cmd/goprecords: CLI with import, query, report-from-files, test - internal/goprecords: types, order, aggregate, db, report - internal/version: version constant (0.1.0) - SQLite import (repeatable: clears record table then inserts) - Magefile: Build, Test, Install, Uninstall - Table-driven unit tests; comparison script vs Raku guprecords - .gitignore: *.db, /goprecords binary Co-authored-by: Cursor <cursoragent@cursor.com>
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..07bfe1c
--- /dev/null
+++ b/Magefile.go
@@ -0,0 +1,65 @@
+//go:build mage
+
+package main
+
+// Magefile for goprecords. Targets follow the same style as other Go projects (e.g. hexai).
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "github.com/magefile/mage/mg"
+ "github.com/magefile/mage/sh"
+)
+
+const binaryName = "goprecords"
+
+// Default builds the binary.
+func Default() { mg.Deps(Build) }
+
+// Build builds the goprecords binary.
+func Build() error {
+ return sh.RunV("go", "build", "-o", binaryName, "./cmd/goprecords")
+}
+
+// Test runs all tests.
+func Test() error {
+ return sh.RunV("go", "test", "./...")
+}
+
+// Install builds and installs the binary to GOPATH/bin.
+func Install() error {
+ mg.Deps(Build)
+ gopath := os.Getenv("GOPATH")
+ if gopath == "" {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return fmt.Errorf("GOPATH unset and home: %w", err)
+ }
+ gopath = filepath.Join(home, "go")
+ }
+ binDir := filepath.Join(gopath, "bin")
+ if err := os.MkdirAll(binDir, 0755); err != nil {
+ return fmt.Errorf("mkdir %s: %w", binDir, err)
+ }
+ dest := filepath.Join(binDir, binaryName)
+ return sh.RunV("cp", "-v", binaryName, dest)
+}
+
+// Uninstall removes the binary from GOPATH/bin.
+func Uninstall() error {
+ gopath := os.Getenv("GOPATH")
+ if gopath == "" {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return fmt.Errorf("GOPATH unset and home: %w", err)
+ }
+ gopath = filepath.Join(home, "go")
+ }
+ dest := filepath.Join(gopath, "bin", binaryName)
+ if err := os.Remove(dest); err != nil && !os.IsNotExist(err) {
+ return err
+ }
+ return nil
+}