From 5e18bcde05db19c0af121f6b165b54d693531a0d Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Tue, 20 Jul 2021 22:50:20 -0500 Subject: [PATCH] trim v from version before updating --- internal/update/update.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/update/update.go b/internal/update/update.go index 0ddd13f..d08400c 100644 --- a/internal/update/update.go +++ b/internal/update/update.go @@ -3,6 +3,7 @@ package update import ( "errors" "spotify/internal" + "strings" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" @@ -24,7 +25,7 @@ func NewCommand() *cobra.Command { return errors.New(internal.ErrAlreadyUpToDate) } - current, err := semver.Parse(cmd.Root().Version) + current, err := parseVersion(cmd) if err != nil { return err } @@ -41,7 +42,7 @@ func NewCommand() *cobra.Command { } func IsUpdated(cmd *cobra.Command) (bool, error) { - current, err := semver.Parse(cmd.Root().Version) + current, err := parseVersion(cmd) if err != nil { return true, err } @@ -54,3 +55,8 @@ func IsUpdated(cmd *cobra.Command) (bool, error) { isUpdated := !found || current.Equals(latest.Version) return isUpdated, nil } + +func parseVersion(cmd *cobra.Command) (semver.Version, error) { + version := strings.TrimPrefix(cmd.Root().Version, "v") + return semver.Parse(version) +}