forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
41 lines (38 loc) · 869 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
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/yaoapp/yao/share"
"runtime"
"strings"
)
var printAllVersion bool
var versionTemplate = `Version: %s
Go version: %s
Git commit: %s
Built: %s
OS/Arch: %s/%s
`
var versionCmd = &cobra.Command{
Use: "version",
Short: L("Show version"),
Long: L("Show version"),
Run: func(cmd *cobra.Command, args []string) {
if printAllVersion {
commit := strings.Split(share.PRVERSION, "-")[0]
buildTime := strings.TrimPrefix(share.PRVERSION, commit+"-")
fmt.Printf(versionTemplate,
share.VERSION,
runtime.Version(),
commit, buildTime,
runtime.GOOS,
runtime.GOARCH)
return
}
// Do Stuff Here
fmt.Println(share.VERSION)
},
}
func init() {
versionCmd.PersistentFlags().BoolVarP(&printAllVersion, "all", "", false, L("Print all version information"))
}