15
16
17
18
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
46
47
48
49
50
|
# File 'lib/wavesync/commands/sync.rb', line 15
def run
options, config = parse_options(banner: 'Usage: wavesync sync [options]') do |opts, opts_hash|
opts.on(*DEVICE_OPTION.to_a) { |value| opts_hash[:device] = value }
opts.on(*PAD_OPTION.to_a) { opts_hash[:pad] = true }
end
device_configs = config.device_configs
if options[:device]
device_configs = device_configs.select { |device_config| device_config[:name] == options[:device] }
if device_configs.empty?
known = config.device_configs.map { |device_config| device_config[:name] }.join(', ')
puts "Unknown device \"#{options[:device]}\". Devices in config: #{known}"
exit 1
end
elsif device_configs.size > 1
device_names = device_configs.map { |device_config| device_config[:name] }
selected_name = Wavesync::UI.new.select('Select device', device_names)
device_configs = device_configs.select { |device_config| device_config[:name] == selected_name }
end
device_pairs = device_configs.map do |device_config|
device = Wavesync::Device.find_by(name: device_config[:model])
unless device
supported = Wavesync::Device.all.map(&:name).join(', ')
puts "Unknown device model \"#{device_config[:model]}\" in config. Supported models: #{supported}"
exit 1
end
[device_config, device]
end
scanner = Wavesync::Scanner.new(config.library)
device_pairs.each do |device_config, device|
scanner.sync(device_config[:path], device, pad: options[:pad] || false)
end
end
|