-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathversion.go
More file actions
46 lines (38 loc) · 771 Bytes
/
version.go
File metadata and controls
46 lines (38 loc) · 771 Bytes
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"
"strings"
"runtime/debug"
"github.com/spf13/cobra"
)
var (
VersionCommand = &cobra.Command{
Use: "version",
Short: "Show version.",
Run: versionInfo,
}
)
func init() {
RootCommand.AddCommand(VersionCommand)
if version == "devel" {
info, ok := debug.ReadBuildInfo()
if ok && strings.HasPrefix(info.Main.Version, "v") {
version = info.Main.Version
}
for _, s := range info.Settings {
switch s.Key {
case "vcs.time":
date = s.Value
case "vcs.revision":
commit = s.Value
case "vcs.modified":
if s.Value == "true" {
commit += "-dirty"
}
}
}
}
}
func versionInfo(cmd *cobra.Command, args []string) {
fmt.Printf("ntt %v, commit %s, built at %s\n", version, commit, date)
}