From 3c2c3cef57e4405fe6814352563a23aaf5101efb Mon Sep 17 00:00:00 2001 From: Oliver Jakoubek Date: Thu, 5 Mar 2026 11:28:44 +0100 Subject: [PATCH] fix: add --version flag and correct ldflags module path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add --version flag to CLI (closes bd-bxt) - Fix ldflags module path: csv2excel/internal/version → code.beautifulmachines.dev/jakoubek/csv2excel/internal/version so build info (version, commit, date) is actually embedded into the binary - Add mg.Deps(Build) to Install so it always builds before installing --- magefiles/magefile.go | 3 ++- main.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/magefiles/magefile.go b/magefiles/magefile.go index d9357e8..0184f1f 100644 --- a/magefiles/magefile.go +++ b/magefiles/magefile.go @@ -28,7 +28,7 @@ func ldflags() (string, error) { buildDate = "unknown" } return fmt.Sprintf( - `-X csv2excel/internal/version.Version=%s -X csv2excel/internal/version.Commit=%s -X csv2excel/internal/version.BuildDate=%s`, + `-X code.beautifulmachines.dev/jakoubek/csv2excel/internal/version.Version=%s -X code.beautifulmachines.dev/jakoubek/csv2excel/internal/version.Commit=%s -X code.beautifulmachines.dev/jakoubek/csv2excel/internal/version.BuildDate=%s`, version, commit, buildDate, ), nil } @@ -77,6 +77,7 @@ func BuildWindows() error { // Install installs the binary to $GOBIN or $GOPATH/bin. func Install() error { + mg.Deps(Build) fmt.Println("Installing", binaryName, "...") flags, err := ldflags() if err != nil { diff --git a/main.go b/main.go index 8fd8b0a..e57192a 100644 --- a/main.go +++ b/main.go @@ -12,14 +12,22 @@ import ( "github.com/xuri/excelize/v2" "golang.org/x/text/encoding/charmap" "golang.org/x/text/transform" + + "code.beautifulmachines.dev/jakoubek/csv2excel/internal/version" ) func main() { sep := flag.String("sep", "auto", "Trennzeichen: auto, ',', ';', '\\t'") enc := flag.String("enc", "utf8", "Encoding: utf8, windows1252") out := flag.String("o", "output.xlsx", "Ausgabedatei") + showVersion := flag.Bool("version", false, "Version anzeigen") flag.Parse() + if *showVersion { + fmt.Printf("csv2excel %s (commit %s, built %s)\n", version.Version, version.Commit, version.BuildDate) + os.Exit(0) + } + files := flag.Args() if len(files) == 0 { fmt.Fprintln(os.Stderr, "Verwendung: csv2xlsx [flags] datei1.csv datei2.csv ...")