-
Notifications
You must be signed in to change notification settings - Fork 25
/
update.go
47 lines (40 loc) · 990 Bytes
/
update.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
package main
import (
"log"
"github.com/blang/semver"
"github.com/rhysd/go-github-selfupdate/selfupdate"
"github.com/urfave/cli"
)
func update(silent bool) error {
if !silent {
log.Printf("Checking for update")
}
v := semver.MustParse(version)
updater, err := selfupdate.NewUpdater(selfupdate.Config{BinaryName: "rainforest"})
if err != nil {
return err
}
latest, err := updater.UpdateSelf(v, "rainforestapp/rainforest-cli")
if err != nil {
return err
}
if !silent && latest.Version.Equals(v) {
log.Println("No update available, already at the latest version!")
} else if latest.Version.NE(v) {
log.Printf("Updated to new version: %s!\n", latest.Version)
}
return nil
}
func updateCmd(c cliContext) error {
err := update(false)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
return nil
}
func autoUpdate(c cliContext, updateFinishedChan chan<- struct{}) {
if !c.Bool("skip-update") {
update(true)
}
updateFinishedChan <- struct{}{}
}