Class: EasyAI::Command::Clean

Inherits:
EasyAI::Command show all
Defined in:
lib/easyai/command/clean.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) ⇒ Clean

Returns a new instance of Clean.



41
42
43
44
45
46
# File 'lib/easyai/command/clean.rb', line 41

def initialize(argv)
  @tool_name = argv.shift_argument || 'claude'
  @force = argv.flag?('force')
  @dry_run = argv.flag?('dry-run')
  super
end

Class Method Details

.optionsObject



34
35
36
37
38
39
# File 'lib/easyai/command/clean.rb', line 34

def self.options
  [
    ['--force', '强制清理,不询问确认'],
    ['--dry-run', '预览将要清理的项目,不执行实际清理'],
  ].concat(super)
end

Instance Method Details

#runObject



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
# File 'lib/easyai/command/clean.rb', line 57

def run
  puts "🧹 准备清理 #{@tool_name == 'all' ? '所有AI工具' : @tool_name.upcase} 的配置信息"
  puts
  
  # 预览模式或确认
  if @dry_run
    puts "📋 预览模式 - 以下项目将被清理:"
    preview_cleanup
    return
  end
  
  unless @force
    puts "⚠️  警告:此操作将删除以下配置信息:"
    preview_cleanup
    puts
    print "确认继续清理?(y/N): "
    confirmation = STDIN.gets.chomp.downcase
    unless confirmation == 'y' || confirmation == 'yes'
      puts "❌ 清理操作已取消"
      return
    end
  end
  
  puts "🧹 开始清理配置..."
  perform_cleanup
  puts "✅ 清理完成"
end

#validate!Object



48
49
50
51
52
53
54
55
# File 'lib/easyai/command/clean.rb', line 48

def validate!
  super
  valid_tools = %w[claude gemini openai all]
  unless valid_tools.include?(@tool_name.downcase)
    help! "不支持的工具名称: #{@tool_name}。支持的工具: #{valid_tools.join(', ')}"
  end
  @tool_name = @tool_name.downcase
end