Class: EasyAI::Command::Clean
- Inherits:
-
EasyAI::Command
- Object
- CLAide::Command
- EasyAI::Command
- EasyAI::Command::Clean
- Defined in:
- lib/easyai/command/clean.rb
Overview
清理 AI CLI 自身在本地产生的缓存与配置目录。
设计要点(详见 docs/设计文档.md §2.6):
- 仅清理三家 AI CLI(claude / gemini / codex)的缓存路径
- 不会触碰 ~/.easyai/config.json(重置 EasyAI 自身配置请用 easyai setup --reset)
- --force 跳过确认;--dry-run 仅打印
- 删除时遇到 Errno::EACCES 继续删余下项;最终如有失败项以退出码 1 退出
Constant Summary collapse
- VALID_TOOLS =
%w[claude gemini codex all].freeze
- CACHE_PATHS =
AI CLI 自身的缓存路径表(不含 ~/.easyai/config.json)
{ 'claude' => %w[~/.claude ~/.claude.json ~/.config/claude], 'gemini' => %w[~/.gemini ~/.config/gemini], 'codex' => %w[~/.codex ~/.config/codex] }.freeze
Constants inherited from EasyAI::Command
DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS
Instance Attribute Summary
Attributes inherited from EasyAI::Command
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Clean
constructor
A new instance of Clean.
- #run ⇒ Object
- #validate! ⇒ Object
Methods inherited from EasyAI::Command
Constructor Details
#initialize(argv) ⇒ Clean
Returns a new instance of Clean.
58 59 60 61 62 63 |
# File 'lib/easyai/command/clean.rb', line 58 def initialize(argv) @tool = (argv.shift_argument || 'claude').to_s.downcase @force = argv.flag?('force') @dry_run = argv.flag?('dry-run') super end |
Class Method Details
.options ⇒ Object
51 52 53 54 55 56 |
# File 'lib/easyai/command/clean.rb', line 51 def self. [ ['--force', '跳过确认提示,直接删除'], ['--dry-run', '仅打印将要删除的路径,不真正删除'] ].concat(super) end |
Instance Method Details
#run ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/easyai/command/clean.rb', line 72 def run targets = collect_targets(@tool) existing = targets.select { |path| File.exist?(path) || File.symlink?(path) } if existing.empty? puts "未找到 #{display_label(@tool)} 的缓存路径,无需清理".cyan return end puts "将清理以下路径(#{display_label(@tool)}):".cyan existing.each { |path| puts " • #{path}" } puts if @dry_run puts "已启用 --dry-run,未执行实际删除。".yellow return end unless @force print "确认继续删除以上路径?(y/N): " answer = ($stdin.gets || '').strip.downcase unless %w[y yes].include?(answer) puts "已取消".yellow return end end failures = perform_delete(existing) if failures.empty? puts "✓ 清理完成".green else puts "⚠ 清理完成,但有 #{failures.size} 项失败".yellow exit 1 end rescue Interrupt puts puts "已取消".yellow exit 130 end |
#validate! ⇒ Object
65 66 67 68 69 70 |
# File 'lib/easyai/command/clean.rb', line 65 def validate! super unless VALID_TOOLS.include?(@tool) help! "不支持的工具:#{@tool}。可选值:#{VALID_TOOLS.join(' / ')}" end end |