feat(updater): 引入 24 小时静默更新检测与一键升级功能
- 新增 `updater` 模块实现 GitHub Release 版本异步检查与本地缓存 - 新增 `git air update` 与 `git air version` 命令支持一键升级及版本检查 - 优化 CLI 终端交互,在首页渲染时提供友好的新版本升级提示卡片
This commit is contained in:
1 parent
10cbfc39a5
commit
7632652b7b
9 files changed
+398
-64
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/unclesam-ly/git-air/internal/ui"
|
||||
"github.com/unclesam-ly/git-air/internal/updater"
|
||||
)
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "查看当前 git-air 版本信息及更新检测",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Printf("git-air %s (%s/%s, Go %s)\n",
|
||||
updater.CurrentVersion,
|
||||
runtime.GOOS,
|
||||
runtime.GOARCH,
|
||||
runtime.Version(),
|
||||
)
|
||||
|
||||
checkFlag, _ := cmd.Flags().GetBool("check")
|
||||
if checkFlag {
|
||||
info := updater.CheckUpdate(true)
|
||||
if info != nil {
|
||||
ui.PrintUpdateBanner(info.CurrentVersion, info.LatestVersion, info.ReleaseURL)
|
||||
} else {
|
||||
ui.PrintSuccess("当前已是最新版本!")
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
versionCmd.Flags().BoolP("check", "c", true, "向 GitHub 检查是否有可用新版本")
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
}
|
||||
Reference in new issue
Block a user