From 37264d4bc3299e2b5d23f4fd563129b38123f778 Mon Sep 17 00:00:00 2001 From: taxintt Date: Tue, 1 Aug 2023 19:29:09 +0900 Subject: [PATCH] fix: specify cmd.Version to embed version info --- .goreleaser.yaml | 4 +++- cmd/version.go | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5ebaa43..aea8bfe 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -13,7 +13,9 @@ builds: - linux - windows - darwin - ldflags: -s -w -X main.version={{.Version}} + ldflags: + - -s -w + - -X github.com/taxintt/tagli/cmd.Version={{.Version}} archives: - format: tar.gz diff --git a/cmd/version.go b/cmd/version.go index 58af9a7..9281794 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" ) -var version string +var Version string = "" func getVersion(version string) string { return fmt.Sprintf(`tagli @@ -23,9 +23,10 @@ var versionCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { info, ok := debug.ReadBuildInfo() if !ok { - version = "unknown" + Version = "unknown" } - fmt.Println(getVersion(info.Main.Version)) + Version = info.Main.Version + fmt.Println(getVersion(Version)) }, Short: "Show cli version info", }