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": "已取消更新",
|
"Canceled upgrade": "已取消更新",
|
||||||
"Error occurred while updating binary: %s": "更新二进制文件时出错: %s",
|
"Error occurred while updating binary: %s": "更新二进制文件时出错: %s",
|
||||||
"🎉Successfully updated to version: %s🎉": "🎉成功更新到版本: %s🎉",
|
"🎉Successfully updated to version: %s🎉": "🎉成功更新到版本: %s🎉",
|
||||||
|
"Print all version information": "显示详细版本信息",
|
||||||
}
|
}
|
||||||
|
|
||||||
// L 多语言切换
|
// L 多语言切换
|
||||||
|
|
|
||||||
|
|
@ -2,23 +2,40 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/yaoapp/yao/share"
|
"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{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: L("Show version"),
|
Short: L("Show version"),
|
||||||
Long: L("Show version"),
|
Long: L("Show version"),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if printAllVersion {
|
||||||
version := share.VERSION
|
commit := strings.Split(share.PRVERSION, "-")[0]
|
||||||
if share.PRVERSION != "" {
|
buildTime := strings.TrimPrefix(share.PRVERSION, commit+"-")
|
||||||
version = fmt.Sprintf("%s-%s", share.VERSION, share.PRVERSION)
|
fmt.Printf(versionTemplate,
|
||||||
|
share.VERSION,
|
||||||
|
runtime.Version(),
|
||||||
|
commit, buildTime,
|
||||||
|
runtime.GOOS,
|
||||||
|
runtime.GOARCH)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do Stuff Here
|
// 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