/
checker.go
executable file
·75 lines (60 loc) · 1.89 KB
/
checker.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
package checker
import (
"fmt"
"strings"
"github.com/abdfnx/resto/tools"
"github.com/abdfnx/resto/core/api"
"github.com/abdfnx/resto/cmd/factory"
"github.com/mgutz/ansi"
"github.com/tidwall/gjson"
tcexe "github.com/Timothee-Cardoso/tc-exe"
)
func Check(buildVersion string) {
cmdFactory := factory.New()
stderr := cmdFactory.IOStreams.ErrOut
latestVersion := api.GetLatest()
isFromHomebrewTap := isUnderHomebrew()
isFromGo := isUnderGo()
isFromUsrBinDir := isUnderUsr()
isFromGHCLI := isUnderGHCLI()
isFromAppData := isUnderAppData()
var command = func() string {
if isFromHomebrewTap {
return "brew upgrade resto"
} else if isFromGo {
return "go get -u github.com/abdfnx/resto"
} else if isFromUsrBinDir {
return "curl -fsSL https://git.io/resto | bash"
} else if isFromGHCLI {
return "gh extention upgrade resto"
} else if isFromAppData {
return "iwr -useb https://git.io/resto-win | iex"
}
return ""
}
if buildVersion != latestVersion && gjson.Get(tools.SettingsContent(), "rs_settings.show_update").Bool() != false {
fmt.Fprintf(stderr, "\n%s %s → %s\n",
ansi.Color("There's a new version of ", "yellow") + ansi.Color("resto", "cyan") + ansi.Color(" is avalaible:", "yellow"),
ansi.Color(buildVersion, "cyan"),
ansi.Color(latestVersion, "cyan"))
if command() != "" {
fmt.Fprintf(stderr, ansi.Color("To upgrade, run: %s\n", "yellow"), ansi.Color(command(), "black:white"))
}
}
}
var restoExe, _ = tcexe.LookPath("resto")
func isUnderHomebrew() bool {
return strings.Contains(restoExe, "brew")
}
func isUnderGo() bool {
return strings.Contains(restoExe, "go")
}
func isUnderUsr() bool {
return strings.Contains(restoExe, "usr")
}
func isUnderAppData() bool {
return strings.Contains(restoExe, "AppData")
}
func isUnderGHCLI() bool {
return strings.Contains(restoExe, "gh")
}