Skip to content

Commit

Permalink
simplify version ldflag
Browse files Browse the repository at this point in the history
  • Loading branch information
brianstrauch committed Jul 21, 2021
1 parent 9b9a66f commit 15a3517
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package main

import (
"fmt"
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"spotify/internal/back"
"spotify/internal/device"
"spotify/internal/login"
Expand All @@ -17,12 +21,11 @@ import (
"spotify/internal/status"
"spotify/internal/unsave"
"spotify/internal/update"
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// version is a linker flag set by goreleaser
var version = "0.0.0"

func main() {
// TODO: https://github.com/spf13/viper/pull/1064
viper.AddConfigPath("$HOME")
Expand All @@ -34,7 +37,7 @@ func main() {
root := &cobra.Command{
Use: "spotify",
Short: "Spotify for the terminal 🎵",
Version: buildVersion(version, commit, date),
Version: version,
PersistentPreRunE: promptUpdate,
}

Expand All @@ -60,24 +63,6 @@ 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
Expand Down

0 comments on commit 15a3517

Please sign in to comment.