forked from hazelops/ize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
55 lines (43 loc) · 1010 Bytes
/
version.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
package commands
import (
"encoding/json"
"log"
"net/http"
"github.com/Masterminds/semver"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
)
var Version = "development"
func NewVersionCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "show IZE version",
Run: func(cmd *cobra.Command, args []string) {
pterm.Info.Printfln("Version: %s", GetVersionNumber())
},
}
return cmd
}
func GetVersionNumber() string {
return Version
}
func CheckLatestRealese() {
_, err := semver.NewVersion(Version)
if err != nil {
return
}
resp, err := http.Get("https://api.github.com/repos/hazelops/ize/releases/latest")
if err != nil {
log.Fatalln(err)
}
var gr gitResponse
if err := json.NewDecoder(resp.Body).Decode(&gr); err != nil {
log.Fatal(err)
}
if Version != gr.Version {
pterm.Warning.Printfln("Newest version is %s current version is %s. Consider upgrading.", gr.Version, Version)
}
}
type gitResponse struct {
Version string `json:"tag_name"`
}