Merge pull request #273 from almas1992/main

[change] optimized version printing
This commit is contained in:
Max 2022-11-22 11:57:39 +08:00 committed by GitHub
commit 2d1d1e201d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 7 deletions

View file

@ -59,6 +59,7 @@ var langs = map[string]string{
"Canceled upgrade": "已取消更新",
"Error occurred while updating binary: %s": "更新二进制文件时出错: %s",
"🎉Successfully updated to version: %s🎉": "🎉成功更新到版本: %s🎉",
"Print all version information": "显示详细版本信息",
}
// L 多语言切换

View file

@ -2,23 +2,40 @@ 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) {
version := share.VERSION
if share.PRVERSION != "" {
version = fmt.Sprintf("%s-%s", share.VERSION, share.PRVERSION)
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(version)
fmt.Println(share.VERSION)
},
}
func init() {
versionCmd.PersistentFlags().BoolVarP(&printAllVersion, "all", "", false, L("Print all version information"))
}