Class: XCCache::Command::Cache::Clean

Inherits:
XCCache::Command::Cache show all
Defined in:
lib/xccache/command/cache/clean.rb

Instance Attribute Summary

Attributes inherited from XCCache::Command

#build_options, #install_options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XCCache::Command

#str_to_sdks

Methods included from XCCache::Config::Mixin

#config

Constructor Details

#initialize(argv) ⇒ Clean

Returns a new instance of Clean.



14
15
16
17
18
19
# File 'lib/xccache/command/cache/clean.rb', line 14

def initialize(argv)
  super
  @all = argv.flag?("all")
  @dry = argv.flag?("dry")
  @targets = argv.arguments!
end

Class Method Details

.optionsObject



7
8
9
10
11
12
# File 'lib/xccache/command/cache/clean.rb', line 7

def self.options
  [
    ["--all", "Whether to remove all cache (default: false)"],
    ["--dry", "Dry run - don't remove cache, just show what shall be removed (default: false)"],
  ].concat(super)
end

Instance Method Details

#runObject



21
22
23
24
25
26
27
28
# File 'lib/xccache/command/cache/clean.rb', line 21

def run
  to_remove = @targets.flat_map { |t| config.spm_cache_dir.glob("#{t}/*") }
  to_remove = config.spm_cache_dir.glob("*/*") if @all
  to_remove.each do |p|
    UI.info("Removing #{p.basename.to_s.yellow}")
    p.rmtree unless @dry
  end
end