-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
56 lines (48 loc) · 1.12 KB
/
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
56
package main
import (
"bytes"
"fmt"
latest "github.com/tcnksm/go-latest"
"time"
)
// Name is cli name
const Name = "rls"
// Version is cli current version
const Version string = "v0.3.0"
// GitCommit is cli current git commit hash
var GitCommit string
const defaultCheckTimeout = 2 * time.Second
// ShowVersion is handler for version command
func ShowVersion() {
version := fmt.Sprintf("%s version %s", Name, Version)
if len(GitCommit) != 0 {
version += fmt.Sprintf(" (%s)", GitCommit)
}
fmt.Println(version)
var buf bytes.Buffer
verCheckCh := make(chan *latest.CheckResponse)
go func() {
fixFunc := latest.DeleteFrontV()
githubTag := &latest.GithubTag{
Owner: "zcong1993",
Repository: "git-release",
FixVersionStrFunc: fixFunc,
}
res, err := latest.Check(githubTag, fixFunc(Version))
if err != nil {
// Don't return error
return
}
verCheckCh <- res
}()
select {
case <-time.After(defaultCheckTimeout):
case res := <-verCheckCh:
if res.Outdated {
fmt.Fprintf(&buf,
"Latest version of rls is v%s, please upgrade!\n",
res.Current)
}
}
fmt.Print(buf.String())
}