Skip to content

Commit

Permalink
trim v from version before updating
Browse files Browse the repository at this point in the history
  • Loading branch information
brianstrauch committed Jul 21, 2021
1 parent d3fcc16 commit 5e18bcd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package update
import (
"errors"
"spotify/internal"
"strings"

"github.com/blang/semver"
"github.com/rhysd/go-github-selfupdate/selfupdate"
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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)
}

0 comments on commit 5e18bcd

Please # to comment.