From f451b660be61d3d3c6721bccd864d0eddbf84ba1 Mon Sep 17 00:00:00 2001 From: Antoine Aflalo <197810+Belphemur@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:22:22 -0400 Subject: [PATCH] fix: get proper version --- .goreleaser.yml | 2 +- cmd/rootcmd.go | 4 ++++ cmd/version_command.go | 21 --------------------- main.go | 7 +++++++ 4 files changed, 12 insertions(+), 22 deletions(-) delete mode 100644 cmd/version_command.go diff --git a/.goreleaser.yml b/.goreleaser.yml index 46f6f43..355e6f2 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -36,7 +36,7 @@ builds: # trims path - -trimpath ldflags: - - -s -w -X meta.Version={{.Version}} -X meta.Commit={{.Commit}} -X meta.Date={{ .CommitDate }} + - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X meta.date={{ .CommitDate }} env: - CGO_ENABLED=0 # config the checksum filename diff --git a/cmd/rootcmd.go b/cmd/rootcmd.go index 9ea70d9..2d3ffc8 100644 --- a/cmd/rootcmd.go +++ b/cmd/rootcmd.go @@ -14,6 +14,10 @@ var rootCmd = &cobra.Command{ Short: "Convert CBZ files using a specified converter", } +func SetVersionInfo(version, commit, date string) { + rootCmd.Version = fmt.Sprintf("%s (Built on %s from Git SHA %s)", version, date, commit) +} + func getPath() string { return filepath.Join(map[string]string{ "windows": filepath.Join(os.Getenv("APPDATA")), diff --git a/cmd/version_command.go b/cmd/version_command.go deleted file mode 100644 index fe71ccf..0000000 --- a/cmd/version_command.go +++ /dev/null @@ -1,21 +0,0 @@ -package cmd - -import ( - "fmt" - "github.com/belphemur/CBZOptimizer/meta" - "github.com/spf13/cobra" -) - -func init() { - command := &cobra.Command{ - Use: "version", - Short: "Print the version of the application", - Long: "Print the version of the application", - Run: VersionCommand, - } - AddCommand(command) -} - -func VersionCommand(_ *cobra.Command, _ []string) { - fmt.Printf("CBZOptimizer %s [%s] built [%s]\n", meta.Version, meta.Commit, meta.Date) -} diff --git a/main.go b/main.go index af3a57c..7032766 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,13 @@ import ( "github.com/belphemur/CBZOptimizer/cmd" ) +var ( + version = "dev" + commit = "none" + date = "unknown" +) + func main() { + cmd.SetVersionInfo(version, commit, date) cmd.Execute() }