8
8
"os"
9
9
"os/signal"
10
10
"runtime"
11
+ "strconv"
11
12
12
13
"github.com/aybabtme/rgbterm"
13
14
"github.com/blang/semver"
@@ -24,9 +25,26 @@ import (
24
25
)
25
26
26
27
var (
27
- Version = & types.Version {Minor : 6 }
28
+ versionMajor string
29
+ versionMinor string
30
+ versionPatch string
31
+ versionPrerelease string
32
+ versionBuild string
33
+ version = func () * types.Version {
34
+ var prerelease []string
35
+ if versionPrerelease != "" {
36
+ prerelease = append (prerelease , versionPrerelease )
37
+ }
38
+ return & types.Version {
39
+ Major : int32 (mustatoi (versionMajor )),
40
+ Minor : int32 (mustatoi (versionMinor )),
41
+ Patch : int32 (mustatoi (versionPatch )),
42
+ Prereleases : prerelease ,
43
+ Build : versionBuild ,
44
+ }
45
+ }()
28
46
semverVersion = func () semver.Version {
29
- v , err := Version .AsSemver ()
47
+ v , err := version .AsSemver ()
30
48
if err != nil {
31
49
panic (err )
32
50
}
@@ -195,7 +213,7 @@ func newApp() *cli.App {
195
213
req := & checkForUpdateReq {
196
214
arch : runtime .GOARCH ,
197
215
os : runtime .GOOS ,
198
- current : Version ,
216
+ current : version ,
199
217
}
200
218
if statefile != nil {
201
219
if statefile .AccountID != nil {
@@ -212,7 +230,10 @@ func newApp() *cli.App {
212
230
app .After = func (c * cli.Context ) error {
213
231
cancel ()
214
232
select {
215
- case res := <- updateRes :
233
+ case res , ok := <- updateRes :
234
+ if ! ok {
235
+ return nil
236
+ }
216
237
if semverVersion .LT (res .sem ) {
217
238
log .Printf ("a new version of humanlog is available: please update" )
218
239
}
@@ -227,7 +248,7 @@ func newApp() *cli.App {
227
248
}
228
249
if updateStatefile {
229
250
if err := state .WriteStateFile (stateFilepath , statefile ); err != nil {
230
- log .Printf ("failed to update statefile" )
251
+ log .Printf ("failed to update statefile: %v" , err )
231
252
}
232
253
}
233
254
default :
@@ -339,7 +360,7 @@ func checkForUpdate(ctx context.Context, req *checkForUpdateReq) <-chan *checkFo
339
360
updateClient := cliupdatev1connect .NewUpdateServiceClient (client , apiURL )
340
361
res , err := updateClient .GetNextUpdate (ctx , & connect.Request [cliupdatepb.GetNextUpdateRequest ]{
341
362
Msg : & cliupdatepb.GetNextUpdateRequest {
342
- CurrentVersion : Version ,
363
+ CurrentVersion : version ,
343
364
AccountId : req .accountID ,
344
365
MachineId : req .machineID ,
345
366
MachineArchitecture : req .arch ,
@@ -372,3 +393,11 @@ func checkForUpdate(ctx context.Context, req *checkForUpdateReq) <-chan *checkFo
372
393
}()
373
394
return out
374
395
}
396
+
397
+ func mustatoi (a string ) int {
398
+ i , err := strconv .Atoi (a )
399
+ if err != nil {
400
+ panic (err )
401
+ }
402
+ return i
403
+ }
0 commit comments