diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-21 10:25:39 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-21 10:25:39 +0200 |
| commit | 32136b8cb18944157ff1f361bc0755f6b627fd47 (patch) | |
| tree | e778661fb464bd53eb81263562bb8bd7b1aa79de /Magefile.go | |
| parent | b3ef6e1b8b8ad5e05d8fd78c9cb1379f56eef854 (diff) | |
Align Go project structure and add Mage targets
Amp-Thread-ID: https://ampcode.com/threads/T-019c7f3b-1326-767b-94d5-366b91eaf712
Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'Magefile.go')
| -rw-r--r-- | Magefile.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Magefile.go b/Magefile.go new file mode 100644 index 0000000..7f63a22 --- /dev/null +++ b/Magefile.go @@ -0,0 +1,52 @@ +//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) +} |
