-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
40 lines (34 loc) · 837 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
package main
import (
"fmt"
"runtime"
"github.com/spf13/cobra"
)
var (
Version = "development"
Hash = "development"
verbose bool
)
var versionCommand = &cobra.Command{
Use: "version",
Short: "print version",
Long: "print version",
Run: func(cmd *cobra.Command, args []string) {
if verbose {
if Version != "development" {
fmt.Printf("version: \t%s\n", Version)
}
if Hash != "development" {
fmt.Printf("commit: \t%s\n", Hash)
}
fmt.Printf("compiler: \t%s (%s)\n", runtime.Version(), runtime.Compiler)
fmt.Printf("platform: \t%s/%s\n", runtime.GOOS, runtime.GOARCH)
} else {
fmt.Println(Version)
}
},
}
func init() {
versionCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, "version, git commit hash, compiler version & platform")
RootCommand.AddCommand(versionCommand)
}