feat: initialer Commit des csv2excel CLI-Tools

Go-CLI-Tool zum Konvertieren von CSV-Dateien in Excel (.xlsx),
mit Mage-Build-System und Architektur-Dokumentation.
This commit is contained in:
Oliver Jakoubek 2026-03-05 10:14:52 +01:00
commit 26b874674f
10 changed files with 328 additions and 0 deletions

5
magefiles/go.mod Normal file
View file

@ -0,0 +1,5 @@
module csv2excel/magefile
go 1.25.0
require github.com/magefile/mage v1.15.0 // indirect

2
magefiles/go.sum Normal file
View file

@ -0,0 +1,2 @@
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=

100
magefiles/magefile.go Normal file
View file

@ -0,0 +1,100 @@
//go:build mage
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
const binaryName = "csv2excel"
func ldflags() (string, error) {
version, err := sh.Output("git", "describe", "--tags", "--always")
if err != nil {
version = "dev"
}
commit, err := sh.Output("git", "rev-parse", "--short", "HEAD")
if err != nil {
commit = "none"
}
buildDate, err := sh.Output("date", "-u", "+%Y-%m-%dT%H:%M:%SZ")
if err != nil {
buildDate = "unknown"
}
return fmt.Sprintf(
`-X csv2excel/internal/version.Version=%s -X csv2excel/internal/version.Commit=%s -X csv2excel/internal/version.BuildDate=%s`,
version, commit, buildDate,
), nil
}
// Build builds the binary for the current platform.
func Build() error {
switch runtime.GOOS {
case "windows":
return BuildWindows()
default:
return BuildLinux()
}
}
// BuildLinux builds a static binary for Linux amd64.
func BuildLinux() error {
mg.Deps(ensureDistDir)
flags, err := ldflags()
if err != nil {
return err
}
out := filepath.Join("dist", binaryName)
env := map[string]string{
"GOOS": "linux",
"GOARCH": "amd64",
"CGO_ENABLED": "0",
}
return sh.RunWithV(env, "go", "build", "-ldflags", flags, "-o", out, ".")
}
// BuildWindows builds a binary for Windows amd64.
func BuildWindows() error {
mg.Deps(ensureDistDir)
flags, err := ldflags()
if err != nil {
return err
}
out := filepath.Join("dist", binaryName+".exe")
env := map[string]string{
"GOOS": "windows",
"GOARCH": "amd64",
"CGO_ENABLED": "0",
}
return sh.RunWithV(env, "go", "build", "-ldflags", flags, "-o", out, ".")
}
// Install installs the binary to $GOBIN or $GOPATH/bin.
func Install() error {
fmt.Println("Installing", binaryName, "...")
flags, err := ldflags()
if err != nil {
return err
}
err = sh.RunV("go", "install", "-ldflags", flags, ".")
if err != nil {
return err
}
fmt.Println("Done.")
return nil
}
// Clean removes the dist/ directory.
func Clean() error {
return sh.Rm("dist")
}
func ensureDistDir() error {
return os.MkdirAll("dist", 0o755)
}