@@ -27,6 +27,7 @@ import (
27
27
"path/filepath"
28
28
"strings"
29
29
"time"
30
+ "unicode/utf8"
30
31
31
32
"github.com/Masterminds/semver/v3"
32
33
"github.com/codefresh-io/cli-v2/pkg/log"
@@ -37,7 +38,7 @@ import (
37
38
// we don't want to slow down the cli so it is noticable
38
39
// so you get 2 seconds to check the version, which should
39
40
// be enough for most configurations
40
- var getVersionTimeout = time .Second * 2
41
+ var getVersionTimeout = time .Second * 30
41
42
42
43
const (
43
44
color = "\u001b [38;5;220m"
@@ -165,21 +166,21 @@ func checkCliVersion(ctx context.Context) {
165
166
return
166
167
}
167
168
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 )
177
178
log .G ().Printf ("%s%s%s" , color , msg , clearColor )
178
179
}
179
180
180
181
func spaceAccordingly (msg string , params ... interface {}) string {
181
182
lines := strings .Split (msg , "\n " )
182
- fullLength := len (lines [0 ])
183
+ fullLength := utf8 . RuneCountInString (lines [0 ])
183
184
tplIdx := 0
184
185
185
186
for idx , line := range lines {
@@ -188,13 +189,15 @@ func spaceAccordingly(msg string, params ...interface{}) string {
188
189
tplIdx ++
189
190
}
190
191
191
- reqSpaceLeft := fullLength - len (line )
192
+ reqSpaceLeft := fullLength - utf8 . RuneCountInString (line )
192
193
space := strings.Builder {}
193
194
space .Grow (reqSpaceLeft )
194
- for i := 0 ; i < reqSpaceLeft ; i ++ {
195
+ for i := 0 ; i < reqSpaceLeft - 1 ; i ++ {
195
196
_ , _ = space .WriteString (" " )
196
197
}
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
+ }
198
201
lines [idx ] = line
199
202
}
200
203
@@ -262,6 +265,10 @@ func downloadAndExtract(ctx context.Context, url, version string) (string, error
262
265
}
263
266
defer res .Body .Close ()
264
267
268
+ if res .StatusCode == http .StatusNotFound {
269
+ return "" , fmt .Errorf ("could not find version %s" , version )
270
+ }
271
+
265
272
var bytes int64
266
273
if bytes , err = io .Copy (tarfile , res .Body ); err != nil {
267
274
return "" , fmt .Errorf ("failed to copy temp version file: %w" , err )
0 commit comments