Class: EasyAI::Command::Update

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

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

run

Constructor Details

#initialize(argv) ⇒ Update

Returns a new instance of Update.



39
40
41
42
43
44
# File 'lib/easyai/command/update.rb', line 39

def initialize(argv)
  @branch = argv.option('branch') || 'master'
  @keep_source = argv.flag?('keep-source')
  @verbose = argv.flag?('verbose')
  super
end

Class Method Details

.optionsObject



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

def self.options
  [
    ['--branch=BRANCH', '指定要安装的分支(默认: master)'],
    ['--keep-source', '保留下载的源代码'],
    ['--verbose', '显示详细输出']
  ].concat(super)
end

Instance Method Details

#runObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/easyai/command/update.rb', line 51

def run
  puts "\n╔#{'' * 58}".cyan
  puts "#{'EasyAI 开发版本更新工具'.center(58)}".cyan
  puts "#{'' * 58}╝\n".cyan
  
  puts "⚠️  注意:此命令仅用于测试开发版本".yellow
  puts "📦 生产环境请使用: #{'gem update easyai'.green}\n\n"
  
  # 确认继续
  unless confirm_update?
    puts "❌ 更新已取消".red
    return
  end
  
  # 创建临时目录
  temp_dir = Dir.mktmpdir('easyai-update-')
  
  begin
    # 克隆仓库
    clone_repository(temp_dir)
    
    # 执行安装脚本
    install_from_source(temp_dir)
    
    # 显示成功信息
    show_success_message
    
  rescue => e
    puts "\n❌ 更新失败: #{e.message}".red
    puts "   请检查网络连接或稍后重试".red
    exit 1
  ensure
    # 清理临时文件
    cleanup_temp_files(temp_dir) unless @keep_source
  end
end

#validate!Object



46
47
48
49
# File 'lib/easyai/command/update.rb', line 46

def validate!
  super
  help! '未找到 git 命令。请先安装 git。' unless git_available?
end