Class: EasyAI::Command::Update

Inherits:
EasyAI::Command show all
Defined in:
lib/easyai/command/update.rb

Overview

通过 RubyGems 自更新 EasyAI 自身。

设计要点(详见 docs/设计文档.md §2.7):

- 用 system('gem', 'update', 'easyai') 触发 RubyGems 自更新
- 不用 exec,便于子进程结束后继续打印中文提示
- 启动时 EasyAIApp 识别到子命令为 update 会跳过强制版本阻塞,避免死循环

Constant Summary

Constants inherited from EasyAI::Command

DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from EasyAI::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EasyAI::Command

#initialize, run, #validate!

Constructor Details

This class inherits a constructor from EasyAI::Command

Class Method Details

.optionsObject



30
31
32
33
34
# File 'lib/easyai/command/update.rb', line 30

def self.options
  [
    ['--verbose', '显示 gem update 命令的完整输出']
  ].concat(super)
end

Instance Method Details

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/easyai/command/update.rb', line 36

def run
  puts "开始更新 EasyAI...".cyan
  puts "正在执行:gem update easyai".cyan

  ok = if @verbose
         system('gem', 'update', 'easyai')
       else
         system('gem', 'update', 'easyai', out: File::NULL, err: File::NULL)
       end

  if ok
    puts "✓ 更新完成".green
    puts "请重新打开终端,然后运行 `easyai --version` 查看新版本".cyan
  else
    puts "✗ 更新失败".red
    puts "请尝试以下排查方式:".yellow
    puts "  • 检查网络连接是否能访问 https://rubygems.org"
    puts "  • 确认 RubyGems 源可用:gem sources -l"
    puts "  • 权限不足时尝试:sudo gem update easyai"
    puts "  • 重新执行并加 --verbose 查看详细输出"
    exit($?.respond_to?(:exitstatus) && $?.exitstatus ? $?.exitstatus : 1)
  end
end