Class: Wavesync::Commands::ClearCache

Inherits:
Command
  • Object
show all
Defined in:
lib/wavesync/commands/clear_cache.rb

Constant Summary collapse

DEVICE_OPTION =
Option.new(short: '-d', long: '--device NAME', description: 'Clear cache for a specific device only')

Instance Method Summary collapse

Methods inherited from Command

#parse_options

Instance Method Details

#runObject

: () -> void



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wavesync/commands/clear_cache.rb', line 18

def run
  options, config = parse_options(banner: 'Usage: wavesync clear-cache [options]') do |opts, opts_hash|
    opts.on(*DEVICE_OPTION.to_a) { |value| opts_hash[:device] = value }
  end

  mtp_devices = config.device_configs.select { |device_config| device_config[:transport] == 'mtp' }
  if options[:device]
    mtp_devices = mtp_devices.select { |device_config| device_config[:name] == options[:device] }
    if mtp_devices.empty?
      puts "No MTP device named \"#{options[:device]}\" found in config."
      exit 1
    end
  end

  if mtp_devices.empty?
    puts 'No MTP devices configured.'
    return
  end

  mtp_devices.each { |device_config| clear_one(device_config[:name]) }
end