44package cmd
55
66import (
7+ "runtime/debug"
8+
79 "github.com/savioxavier/termlink"
810 "github.com/spf13/cobra"
911)
1012
1113const (
12- versionShort = "Show the version of yutu"
13- versionLong = "Show the version of yutu"
14+ verShort = "Show the version of yutu"
15+ verLong = "Show the version of yutu"
16+ repo = "Github/eat-pray-ai/yutu"
17+ repoUrl = "https://github.com/eat-pray-ai/yutu"
1418)
1519
1620var (
@@ -19,20 +23,37 @@ var (
1923 CommitDate = ""
2024 Os = ""
2125 Arch = ""
22- repo = "https://github.com/eat-pray-ai/yutu "
26+ Builder = "Gopher "
2327)
2428
2529var versionCmd = & cobra.Command {
2630 Use : "version" ,
27- Short : versionShort ,
28- Long : versionLong ,
31+ Short : verShort ,
32+ Long : verLong ,
2933 Run : func (cmd * cobra.Command , args []string ) {
30- cmd .Printf ("🐰yutu version %s %s/%s" , Version , Os , Arch )
31- if Commit != "" && CommitDate != "" {
32- cmd .Printf ("\n 📦build %s-%s" , Commit , CommitDate )
34+ info , ok := debug .ReadBuildInfo ()
35+ if ok && Version == "" {
36+ Version = info .Main .Version
37+
38+ settings := make (map [string ]string )
39+ for _ , setting := range info .Settings {
40+ settings [setting .Key ] = setting .Value
41+ }
42+
43+ if val , exists := settings ["vcs.time" ]; exists {
44+ CommitDate = val
45+ }
46+ if val , exists := settings ["GOOS" ]; exists {
47+ Os = val
48+ }
49+ if val , exists := settings ["GOARCH" ]; exists {
50+ Arch = val
51+ }
3352 }
3453
35- cmd .Println ("\n 🌟Star:" , termlink .Link ("Github/eat-pray-ai/yutu" , repo ))
54+ cmd .Printf ("🐰yutu %s %s/%s\n " , Version , Os , Arch )
55+ cmd .Printf ("📦build %s-%s\n " , Builder , CommitDate )
56+ cmd .Printf ("🌟Star: %s\n " , termlink .Link (repo , repoUrl ))
3657 },
3758}
3859
0 commit comments