-
Notifications
You must be signed in to change notification settings - Fork 232
/
check.go
83 lines (65 loc) · 1.66 KB
/
check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package cmd
import (
"log"
"os"
"time"
"github.com/CircleCI-Public/circleci-cli/settings"
"github.com/CircleCI-Public/circleci-cli/update"
"github.com/CircleCI-Public/circleci-cli/version"
"github.com/briandowns/spinner"
)
func checkForUpdates(opts *settings.Config) error {
if opts.SkipUpdateCheck {
return nil
}
updateCheck := &settings.UpdateCheck{
LastUpdateCheck: time.Time{},
}
err := updateCheck.Load()
if err != nil {
return err
}
if update.ShouldCheckForUpdates(updateCheck) {
log := log.New(os.Stderr, "", 0)
slug := "CircleCI-Public/circleci-cli"
spr := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
spr.Writer = os.Stderr
spr.Suffix = " Checking for updates..."
spr.Start()
check, err := update.CheckForUpdates(opts.GitHubAPI, slug, version.Version, version.PackageManager())
if err != nil {
spr.Stop()
return err
}
if !check.Found {
spr.Suffix = "No updates found."
time.Sleep(300 * time.Millisecond)
spr.Stop()
updateCheck.LastUpdateCheck = time.Now()
err = updateCheck.WriteToDisk()
return err
}
if update.IsLatestVersion(check) {
spr.Suffix = "Already up-to-date."
time.Sleep(300 * time.Millisecond)
spr.Stop()
updateCheck.LastUpdateCheck = time.Now()
err = updateCheck.WriteToDisk()
return err
}
spr.Stop()
if opts.Debug {
log.Println(update.DebugVersion(check))
log.Println("")
}
log.Println(update.ReportVersion(check))
log.Println(update.HowToUpdate(check))
log.Println("") // Print a new-line after all of that
updateCheck.LastUpdateCheck = time.Now()
err = updateCheck.WriteToDisk()
if err != nil {
return err
}
}
return nil
}