Skip to content

Commit

Permalink
fix subcmd/update
Browse files Browse the repository at this point in the history
  • Loading branch information
utahta committed Feb 11, 2020
1 parent fec1d82 commit 8e866c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 15 additions & 1 deletion subcmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"

"github.com/blang/semver"
"github.com/pkg/errors"
)

var Version string
var (
Version string

reVersion = regexp.MustCompile(`\d+\.\d+\.\d+`)
)

type (
// Command sub command interface
Expand Down Expand Up @@ -81,3 +87,11 @@ PYTHONBREW_VERSION_LIB=%s
fp.WriteString(env)
return nil
}

func semverVersion() semver.Version {
v := Version
if loc := reVersion.FindStringIndex(v); loc != nil && loc[0] > 0 {
v = v[loc[0]:]
}
return semver.MustParse(v)
}
3 changes: 1 addition & 2 deletions subcmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package subcmd
import (
"flag"

"github.com/blang/semver"
"github.com/pkg/errors"
"github.com/rhysd/go-github-selfupdate/selfupdate"
"github.com/utahta/pythonbrew/flagset"
Expand Down Expand Up @@ -56,7 +55,7 @@ func (c *Update) Run(args []string) error {
return nil
}

previous := semver.MustParse(Version)
previous := semverVersion()
latest, err := selfupdate.UpdateSelf(previous, "utahta/pythonbrew")
if err != nil {
return errors.Wrap(err, tag)
Expand Down

0 comments on commit 8e866c8

Please sign in to comment.