Skip to content

Commit f547694

Browse files
author
Quentin Perez
committed
Print a message if a newest version is available
1 parent 620dcf5 commit f547694

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ REL_PACKAGES := $(subst $(GODIR),./,$(PACKAGES))
3535
VERSION = $(shell cat .goxc.json | grep "PackageVersion" | egrep -o "([0-9]{1,}\.)+[0-9]{1,}")
3636
REV = $(shell git rev-parse HEAD || echo "nogit")
3737
TAG = $(shell git describe --tags --always || echo $(VERSION) || echo "nogit")
38-
LDFLAGS = "-X github.com/scaleway/scaleway-cli/pkg/scwversion.GITCOMMIT=$(REV) \
39-
-X github.com/scaleway/scaleway-cli/pkg/scwversion.VERSION=$(TAG)"
38+
LDFLAGS = "-X github.com/scaleway/scaleway-cli/pkg/scwversion.GITCOMMIT=$(REV)"
4039
BUILDER = scaleway-cli-builder
4140

4241
# Check go version

pkg/cli/main.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ package cli
77
import (
88
"fmt"
99
"io/ioutil"
10+
"net/http"
1011
"os"
1112
"path/filepath"
13+
"strings"
1214
"time"
1315

1416
"github.com/Sirupsen/logrus"
1517
flag "github.com/docker/docker/pkg/mflag"
18+
"github.com/hashicorp/go-version"
1619

1720
"github.com/scaleway/scaleway-cli/pkg/api"
1821
"github.com/scaleway/scaleway-cli/pkg/commands"
@@ -194,5 +197,34 @@ func checkVersion() {
194197
return
195198
}
196199
scwupdate.Close()
200+
req := http.Client{
201+
Timeout: time.Duration(1 * time.Second),
202+
}
203+
resp, err := req.Get("https://fr-1.storage.online.net/scaleway/scaleway-cli/VERSION")
204+
if resp != nil {
205+
defer resp.Body.Close()
206+
}
207+
if err != nil {
208+
return
209+
}
210+
body, err := ioutil.ReadAll(resp.Body)
211+
if err != nil {
212+
return
213+
}
214+
if scwversion.VERSION == "" {
215+
return
216+
}
217+
ver := scwversion.VERSION
218+
if ver[0] == 'v' {
219+
ver = string([]byte(ver)[1:])
220+
}
221+
actual, err1 := version.NewVersion(ver)
222+
update, err2 := version.NewVersion(strings.Trim(string(body), "\n"))
223+
if err1 != nil || err2 != nil {
224+
return
225+
}
226+
if actual.LessThan(update) {
227+
logrus.Infof("A new version of scw is available (%v), beware that you are currently running %v", update, actual)
228+
}
197229
}
198230
}

0 commit comments

Comments
 (0)