@@ -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
4243const (
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
180181func 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