From 8e866c8fa22f7527d92e38b75e1b83f69eb685c7 Mon Sep 17 00:00:00 2001 From: utahta Date: Tue, 11 Feb 2020 18:22:10 +0900 Subject: [PATCH] fix subcmd/update --- subcmd/command.go | 16 +++++++++++++++- subcmd/update.go | 3 +-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/subcmd/command.go b/subcmd/command.go index 1885968..8f894f3 100644 --- a/subcmd/command.go +++ b/subcmd/command.go @@ -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 @@ -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) +} diff --git a/subcmd/update.go b/subcmd/update.go index c4aadec..59c8897 100644 --- a/subcmd/update.go +++ b/subcmd/update.go @@ -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" @@ -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)