This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.go
executable file
·63 lines (50 loc) · 1.5 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
package checker
import (
"fmt"
"strings"
"github.com/mgutz/ansi"
"github.com/abdfnx/looker"
"github.com/abdfnx/instal/api"
"github.com/abdfnx/instal/cmd/factory"
)
func Check(buildVersion string) {
cmdFactory := factory.New()
stderr := cmdFactory.IOStreams.ErrOut
latestVersion := api.GetLatest()
isFromHomebrewTap := isUnderHomebrew()
isFromUsrBinDir := isUnderUsr()
isFromGHCLI := isUnderGHCLI()
isFromAppData := isUnderAppData()
var command = func() string {
if isFromHomebrewTap {
return "brew upgrade instal"
} else if isFromUsrBinDir || isFromAppData {
return "instal https://bit.ly/instal-cli"
} else if isFromGHCLI {
return "gh extention upgrade instal"
}
return ""
}
if buildVersion != latestVersion {
fmt.Fprintf(stderr, "%s %s → %s\n",
ansi.Color("There's a new version of ", "yellow") + ansi.Color("instal", "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 instalExe, _ = looker.LookPath("instal")
func isUnderHomebrew() bool {
return strings.Contains(instalExe, "brew")
}
func isUnderUsr() bool {
return strings.Contains(instalExe, "usr")
}
func isUnderAppData() bool {
return strings.Contains(instalExe, "AppData")
}
func isUnderGHCLI() bool {
return strings.Contains(instalExe, "gh")
}