-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.go
46 lines (39 loc) · 997 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
package main
import (
"fmt"
"os"
"runtime/debug"
"text/tabwriter"
)
var version = "devel"
func printVersionInfo(info *debug.BuildInfo) {
fmt.Printf("%s %s\n\n", projectName, version)
fmt.Print("Build Information:\n\n")
buildtw := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0)
fmt.Fprintf(buildtw, "Go version:\t%s\n", info.GoVersion)
for _, setting := range info.Settings {
key := setting.Key
value := setting.Value
switch setting.Key {
case "-compiler":
key = "Compiler"
case "-ldflags":
key = "Link Flags"
case "vcs", "vcs.modified":
continue
case "vcs.revision":
key = "Commit"
case "vcs.time":
key = "Commit Time"
}
fmt.Fprintf(buildtw, "%s:\t%s\n", key, value)
}
buildtw.Flush()
fmt.Print("\nDependencies:\n\n")
deptw := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0)
fmt.Fprint(deptw, "Name\tVersion\tHash\n")
for _, dep := range info.Deps {
fmt.Fprintf(deptw, "%s\t%s\t%s\n", dep.Path, dep.Version, dep.Sum)
}
deptw.Flush()
}