Skip to content

Commit

Permalink
Merge pull request #8 from taxintt/fix/embed-version-to-specified-var
Browse files Browse the repository at this point in the history
fix: specify cmd.Version to embed version info
  • Loading branch information
taxintt authored Aug 1, 2023
2 parents 47c355d + 37264d4 commit c99a4d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
)

var version string
var Version string = ""

func getVersion(version string) string {
return fmt.Sprintf(`tagli
Expand All @@ -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",
}
Expand Down

0 comments on commit c99a4d1

Please sign in to comment.