From 4bb202ee5091433cc0d1266a57451d0b93da06b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= <1009277+imiric@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:05:13 +0200 Subject: [PATCH] Expand version output to include Go version and arch info --- cmd/buildinfo.go | 13 +++++++++++-- cmd/root.go | 2 +- goreleaser.yml | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/buildinfo.go b/cmd/buildinfo.go index 8112766..67dea49 100644 --- a/cmd/buildinfo.go +++ b/cmd/buildinfo.go @@ -1,11 +1,15 @@ package cmd +import ( + "fmt" + "runtime" +) + // Field injected by goreleaser var ( version = "" commitDate = "date unknown" commit = "" - target = "" ) func Version() string { @@ -21,5 +25,10 @@ func Commit() string { } func Target() string { - return target + return runtime.GOOS +} + +func FullVersion() string { + return fmt.Sprintf("%s %s/%s %s (%s) %s", + version, runtime.GOOS, runtime.GOARCH, runtime.Version(), commitDate, commit) } diff --git a/cmd/root.go b/cmd/root.go index d998e6b..52c283c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -19,7 +19,7 @@ func Execute() { rootCmd.PersistentFlags(). String("config", "tygo.yaml", "config file to load (default is tygo.yaml in the current folder)") - rootCmd.Version = Version() + " " + Target() + " (" + CommitDate() + ") " + Commit() + rootCmd.Version = FullVersion() rootCmd.PersistentFlags().BoolP("debug", "D", false, "Debug mode (prints debug messages)") rootCmd.AddCommand(&cobra.Command{ diff --git a/goreleaser.yml b/goreleaser.yml index a3e8225..445415a 100644 --- a/goreleaser.yml +++ b/goreleaser.yml @@ -8,7 +8,7 @@ builds: goarch: - amd64 ldflags: - - -s -w -X github.com/gzuidhof/tygo/cmd.version={{.Version}} -X github.com/gzuidhof/tygo/cmd.commit={{.Commit}} -X github.com/gzuidhof/tygo/cmd.commitDate={{.CommitDate}} -X github.com/gzuidhof/tygo/cmd.target={{.Env.GOOS}} + - -s -w -X github.com/gzuidhof/tygo/cmd.version={{.Version}} -X github.com/gzuidhof/tygo/cmd.commit={{.Commit}} -X github.com/gzuidhof/tygo/cmd.commitDate={{.CommitDate}} archives: - id: tygo name_template: >-