Skip to content

Commit a5ba18c

Browse files
committed
feat: add --version support
1 parent ffcbeae commit a5ba18c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cmd/codei18n/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
var (
1212
cfgFile string
1313
verbose bool
14+
version = "dev" // Override at build time via -ldflags "-X main.version=<version>"
1415
)
1516

1617
// rootCmd represents the base command when called without any subcommands
@@ -32,6 +33,9 @@ func Execute() {
3233
func init() {
3334
cobra.OnInitialize(initConfig)
3435

36+
rootCmd.Version = version
37+
rootCmd.SetVersionTemplate("CodeI18n CLI 版本: {{.Version}}\n")
38+
3539
// Global flags
3640
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "配置文件路径 (默认是 $HOME/.codei18n.json 或项目根目录 .codei18n/config.json)")
3741
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "显示详细日志")

0 commit comments

Comments
 (0)