Skip to content

Commit 4b4cff7

Browse files
improved upgrade message and fix version not found message (#653)
1 parent 0fc5100 commit 4b4cff7

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.1.13
1+
VERSION=v0.1.14
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.13/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.14/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.13/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.14/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

pkg/util/cli/cli.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"path/filepath"
2828
"strings"
2929
"time"
30+
"unicode/utf8"
3031

3132
"github.com/Masterminds/semver/v3"
3233
"github.com/codefresh-io/cli-v2/pkg/log"
@@ -37,7 +38,7 @@ import (
3738
// we don't want to slow down the cli so it is noticable
3839
// so you get 2 seconds to check the version, which should
3940
// be enough for most configurations
40-
var getVersionTimeout = time.Second * 2
41+
var getVersionTimeout = time.Second * 30
4142

4243
const (
4344
color = "\u001b[38;5;220m"
@@ -165,21 +166,21 @@ func checkCliVersion(ctx context.Context) {
165166
return
166167
}
167168

168-
msg := spaceAccordingly(`***********************************
169-
** Newer version is available!
170-
**
171-
** Current: %s
172-
** Latest: %s
173-
**
174-
** To get the latest version
175-
** run: %s upgrade
176-
***********************************`, curV, v, store.Get().BinaryName)
169+
msg := spaceAccordingly(`╔═════════════════════════════════╗
170+
Newer version is available!
171+
172+
Current: %s
173+
Latest: %s
174+
175+
To get the latest version
176+
run: %s upgrade
177+
╚═════════════════════════════════╝`, curV, v, store.Get().BinaryName)
177178
log.G().Printf("%s%s%s", color, msg, clearColor)
178179
}
179180

180181
func spaceAccordingly(msg string, params ...interface{}) string {
181182
lines := strings.Split(msg, "\n")
182-
fullLength := len(lines[0])
183+
fullLength := utf8.RuneCountInString(lines[0])
183184
tplIdx := 0
184185

185186
for idx, line := range lines {
@@ -188,13 +189,15 @@ func spaceAccordingly(msg string, params ...interface{}) string {
188189
tplIdx++
189190
}
190191

191-
reqSpaceLeft := fullLength - len(line)
192+
reqSpaceLeft := fullLength - utf8.RuneCountInString(line)
192193
space := strings.Builder{}
193194
space.Grow(reqSpaceLeft)
194-
for i := 0; i < reqSpaceLeft; i++ {
195+
for i := 0; i < reqSpaceLeft-1; i++ {
195196
_, _ = space.WriteString(" ")
196197
}
197-
line = fmt.Sprintf("%s%s**", line, space.String())
198+
if idx != 0 && idx != len(lines)-1 {
199+
line = fmt.Sprintf("%s%s║", line, space.String())
200+
}
198201
lines[idx] = line
199202
}
200203

@@ -262,6 +265,10 @@ func downloadAndExtract(ctx context.Context, url, version string) (string, error
262265
}
263266
defer res.Body.Close()
264267

268+
if res.StatusCode == http.StatusNotFound {
269+
return "", fmt.Errorf("could not find version %s", version)
270+
}
271+
265272
var bytes int64
266273
if bytes, err = io.Copy(tarfile, res.Body); err != nil {
267274
return "", fmt.Errorf("failed to copy temp version file: %w", err)

0 commit comments

Comments
 (0)