fix: add --version flag and correct ldflags module path

- 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
This commit is contained in:
Oliver Jakoubek 2026-03-05 11:28:44 +01:00
commit 3c2c3cef57
2 changed files with 10 additions and 1 deletions

View file

@ -28,7 +28,7 @@ func ldflags() (string, error) {
buildDate = "unknown" buildDate = "unknown"
} }
return fmt.Sprintf( 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, version, commit, buildDate,
), nil ), nil
} }
@ -77,6 +77,7 @@ func BuildWindows() error {
// Install installs the binary to $GOBIN or $GOPATH/bin. // Install installs the binary to $GOBIN or $GOPATH/bin.
func Install() error { func Install() error {
mg.Deps(Build)
fmt.Println("Installing", binaryName, "...") fmt.Println("Installing", binaryName, "...")
flags, err := ldflags() flags, err := ldflags()
if err != nil { if err != nil {

View file

@ -12,14 +12,22 @@ import (
"github.com/xuri/excelize/v2" "github.com/xuri/excelize/v2"
"golang.org/x/text/encoding/charmap" "golang.org/x/text/encoding/charmap"
"golang.org/x/text/transform" "golang.org/x/text/transform"
"code.beautifulmachines.dev/jakoubek/csv2excel/internal/version"
) )
func main() { func main() {
sep := flag.String("sep", "auto", "Trennzeichen: auto, ',', ';', '\\t'") sep := flag.String("sep", "auto", "Trennzeichen: auto, ',', ';', '\\t'")
enc := flag.String("enc", "utf8", "Encoding: utf8, windows1252") enc := flag.String("enc", "utf8", "Encoding: utf8, windows1252")
out := flag.String("o", "output.xlsx", "Ausgabedatei") out := flag.String("o", "output.xlsx", "Ausgabedatei")
showVersion := flag.Bool("version", false, "Version anzeigen")
flag.Parse() 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() files := flag.Args()
if len(files) == 0 { if len(files) == 0 {
fmt.Fprintln(os.Stderr, "Verwendung: csv2xlsx [flags] datei1.csv datei2.csv ...") fmt.Fprintln(os.Stderr, "Verwendung: csv2xlsx [flags] datei1.csv datei2.csv ...")