Merge pull request #273 from almas1992/main
[change] optimized version printing
This commit is contained in:
commit
2d1d1e201d
2 changed files with 25 additions and 7 deletions
|
|
@ -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 多语言切换
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue