forked from keploy/keploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·71 lines (57 loc) · 1.74 KB
/
main.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
package main
import (
"fmt"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
v "github.com/hashicorp/go-version"
"go.keploy.io/server/cmd"
)
// version is the version of the server and will be injected during build by ldflags
// see https://goreleaser.com/customization/build/
var version string
const logo string = `
▓██▓▄
▓▓▓▓██▓█▓▄
████████▓▒
▀▓▓███▄ ▄▄ ▄ ▌
▄▌▌▓▓████▄ ██ ▓█▀ ▄▌▀▄ ▓▓▌▄ ▓█ ▄▌▓▓▌▄ ▌▌ ▓
▓█████████▌▓▓ ██▓█▄ ▓█▄▓▓ ▐█▌ ██ ▓█ █▌ ██ █▌ █▓
▓▓▓▓▀▀▀▀▓▓▓▓▓▓▌ ██ █▓ ▓▌▄▄ ▐█▓▄▓█▀ █▓█ ▀█▄▄█▀ █▓█
▓▌ ▐█▌ █▌
▓
`
func getKeployVersion() string {
repo, err := git.PlainOpen(".")
if err != nil {
return "v0.1.0-dev"
}
tagIter, err := repo.Tags()
if err != nil {
return "v0.1.0-dev"
}
var latestTag string
var latestTagVersion *v.Version
err = tagIter.ForEach(func(tagRef *plumbing.Reference) error {
tagName := tagRef.Name().Short()
tagVersion, err := v.NewVersion(tagName)
if err == nil {
if latestTagVersion == nil || latestTagVersion.LessThan(tagVersion) {
latestTagVersion = tagVersion
latestTag = tagName
}
}
return nil
})
if err != nil {
return "v0.1.0-dev"
}
return latestTag + "-dev"
}
func main() {
if version == "" {
version = getKeployVersion()
}
fmt.Println(logo, " ")
fmt.Printf("%v\n\n", version)
cmd.Execute()
}