Class: DiffGem::CacheCommands

Inherits:
Thor
  • Object
show all
Defined in:
lib/diff_gem/cli.rb

Instance Method Summary collapse

Instance Method Details

#clearObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/diff_gem/cli.rb', line 7

def clear
  cache_dir = ENV['DIFF_GEM_CACHE_DIR'] || File.expand_path('~/.diff_gem_cache')

  if File.exist?(cache_dir)
    FileUtils.rm_rf(cache_dir)
    puts "Cache cleared: #{cache_dir}"
  else
    puts "Cache directory does not exist: #{cache_dir}"
  end
end

#infoObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/diff_gem/cli.rb', line 19

def info
  cache_dir = ENV['DIFF_GEM_CACHE_DIR'] || File.expand_path('~/.diff_gem_cache')

  puts "Cache directory: #{cache_dir}"

  if File.exist?(cache_dir)
    gem_dirs = Dir.glob(File.join(cache_dir, '*', '*')).select { |f| File.directory?(f) }

    size = `du -sh "#{cache_dir}" 2>/dev/null`.split.first rescue "unknown"

    puts "Status: exists"
    puts "Size: #{size}"
    puts "Cached gem versions: #{gem_dirs.length}"

    if gem_dirs.any?
      puts "\nCached gems:"
      gem_dirs.each do |dir|
        parts = dir.split('/')
        version = parts[-1]
        name = parts[-2]
        puts "  #{name} #{version}"
      end
    end
  else
    puts "Status: does not exist"
  end
end