-
Notifications
You must be signed in to change notification settings - Fork 17
/
cmd-version.go
57 lines (52 loc) · 1.08 KB
/
cmd-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
57
package main
import (
"fmt"
"runtime/debug"
"github.com/urfave/cli/v2"
)
func newCmd_Version() *cli.Command {
return &cli.Command{
Name: "version",
Usage: "Print version information of this binary.",
Description: "Print version information of this binary.",
Before: func(c *cli.Context) error {
return nil
},
Flags: []cli.Flag{},
Action: func(c *cli.Context) error {
fmt.Println("YELLOWSTONE FAITHFUL CLI")
fmt.Printf("Tag/Branch: %s\n", GitTag)
fmt.Printf("Commit: %s\n", GitCommit)
if info, ok := debug.ReadBuildInfo(); ok {
fmt.Printf("More info:\n")
for _, setting := range info.Settings {
if isAnyOf(setting.Key,
"-compiler",
"GOARCH",
"GOOS",
"GOAMD64",
"vcs",
"vcs.revision",
"vcs.time",
"vcs.modified",
) {
fmt.Printf(" %s: %s\n", setting.Key, setting.Value)
}
}
}
return nil
},
}
}
var (
GitCommit string
GitTag string
)
func isAnyOf(s string, anyOf ...string) bool {
for _, v := range anyOf {
if s == v {
return true
}
}
return false
}