@@ -15,11 +15,11 @@ import (
1515 "codes/internal/ui"
1616)
1717
18- func runVersion () {
18+ func RunVersion () {
1919 fmt .Printf ("codes version dev (built unknown)\n " )
2020}
2121
22- func runSelect () {
22+ func RunSelect () {
2323 // Load config
2424 cfg , err := config .LoadConfig ()
2525 if err != nil {
@@ -65,7 +65,7 @@ func runSelect() {
6565 if selection == "" {
6666 // 直接启动Claude
6767 ui .ShowSuccess ("Starting with current configuration..." )
68- runClaudeWithConfig ([]string {})
68+ RunClaudeWithConfig ([]string {})
6969 return
7070 }
7171
@@ -83,14 +83,14 @@ func runSelect() {
8383 ui .ShowInfo ("API: %s" , selectedConfig .AnthropicBaseURL )
8484
8585 // 立即启动Claude
86- runClaudeWithConfig ([]string {})
86+ RunClaudeWithConfig ([]string {})
8787 } else {
8888 ui .ShowWarning ("Invalid selection, starting with current config..." )
89- runClaudeWithConfig ([]string {})
89+ RunClaudeWithConfig ([]string {})
9090 }
9191}
9292
93- func runUpdate () {
93+ func RunUpdate () {
9494 ui .ShowHeader ("Claude Version Manager" )
9595 ui .ShowLoading ("Fetching available versions..." )
9696
@@ -138,7 +138,7 @@ func runUpdate() {
138138 }
139139}
140140
141- func runAdd () {
141+ func RunAdd () {
142142 ui .ShowHeader ("Add New Claude Configuration" )
143143
144144 // 检查是否已存在配置文件,如果不存在则创建
@@ -239,7 +239,7 @@ func runAdd() {
239239 }
240240}
241241
242- func runInstall () {
242+ func RunInstall () {
243243 ui .ShowHeader ("Installing codes CLI" )
244244
245245 // 获取当前可执行文件路径
@@ -312,7 +312,10 @@ func runInstall() {
312312 }
313313}
314314
315- func runClaudeWithConfig (args []string ) {
315+ func RunClaudeWithConfig (args []string ) {
316+ // 调用更新检查
317+ checkForUpdates ()
318+
316319 // Load and apply config
317320 cfg , err := config .LoadConfig ()
318321 if err != nil {
@@ -331,7 +334,7 @@ func runClaudeWithConfig(args []string) {
331334
332335 // Set environment variables
333336 os .Setenv ("ANTHROPIC_BASE_URL" , selectedConfig .AnthropicBaseURL )
334- os .Setenv ("ANTROPIC_AUTH_TOKEN " , selectedConfig .AnthropicAuthToken )
337+ os .Setenv ("ANTHROPIC_AUTH_TOKEN " , selectedConfig .AnthropicAuthToken )
335338
336339 ui .ShowInfo ("Using configuration: %s (%s)" , selectedConfig .Name , selectedConfig .AnthropicBaseURL )
337340 // Run claude with dangerous permissions
@@ -342,6 +345,10 @@ func runClaudeWithConfig(args []string) {
342345 cmd .Run ()
343346}
344347
348+ func InstallClaude (version string ) {
349+ installClaude (version )
350+ }
351+
345352func installClaude (version string ) {
346353 cmd := exec .Command ("npm" , "install" , "-g" , fmt .Sprintf ("@anthropic-ai/claude-code@%s" , version ))
347354 cmd .Stdout = os .Stdout
@@ -351,4 +358,34 @@ func installClaude(version string) {
351358 os .Exit (1 )
352359 }
353360 ui .ShowSuccess ("Claude installed successfully!" )
354- }
361+ }
362+
363+ func checkForUpdates () {
364+ // 检查codes CLI更新
365+ go func () {
366+ // 简单的版本检查逻辑
367+ // 这里可以集成GitHub API检查最新版本
368+ // 目前只是占位符
369+ // 可以通过检查GitHub releases API来获取最新版本
370+ // 例如: https://api.github.com/repos/{owner}/{repo}/releases/latest
371+ // 然后与当前版本比较,提示用户更新
372+ //
373+ // 示例实现:
374+ // resp, err := http.Get("https://api.github.com/repos/yourusername/codes/releases/latest")
375+ // if err != nil {
376+ // return
377+ // }
378+ // defer resp.Body.Close()
379+ //
380+ // var release struct {
381+ // TagName string `json:"tag_name"`
382+ // }
383+ // if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
384+ // return
385+ // }
386+ //
387+ // if release.TagName != "dev" && release.TagName != currentVersion {
388+ // ui.ShowInfo("New version %s available! Run 'codes update' to upgrade.", release.TagName)
389+ // }
390+ }()
391+ }
0 commit comments