From 9b9a66f295a1d55e06201ecf90fe5914d3320240 Mon Sep 17 00:00:00 2001 From: "O.J" <4623930+OrlovEvgeny@users.noreply.github.com> Date: Wed, 21 Jul 2021 05:53:03 +0300 Subject: [PATCH] Resolve issue https://github.com/brianstrauch/spotify-cli/issues/30 (#43) Co-authored-by: Evgenii Orlov --- main.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 3da279d..63e374e 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "spotify/internal/back" "spotify/internal/device" "spotify/internal/login" @@ -33,7 +34,7 @@ func main() { root := &cobra.Command{ Use: "spotify", Short: "Spotify for the terminal 🎵", - Version: "1.9.2", + Version: buildVersion(version, commit, date), PersistentPreRunE: promptUpdate, } @@ -59,6 +60,24 @@ func main() { _ = root.Execute() } +// Sets ldflags by goreleaser https://goreleaser.com/customization/build/ (default values) +var ( + version = "dev" + commit string + date string +) + +func buildVersion(version, commit, date string) string { + result := version + if commit != "" { + result = fmt.Sprintf("%s\ncommit: %s", result, commit) + } + if date != "" { + result = fmt.Sprintf("%s\nbuilt at: %s", result, date) + } + return result +} + func promptUpdate(cmd *cobra.Command, _ []string) error { if time.Now().Unix() < viper.GetInt64("prompt_update_timer") { return nil