lib/snapshot/reset_simulators.rb in snapshot-1.12.2 vs lib/snapshot/reset_simulators.rb in snapshot-1.12.3
- old
+ new
@@ -33,20 +33,11 @@
else
create(device_type, ios_versions)
end
end
- phones = []
- watches = []
- devices.each do |device|
- _, name, id = device
- phones << id if name.start_with?('iPhone 6')
- watches << id if name.end_with?('mm')
- end
-
- puts "Creating device pair of #{phones.last} and #{watches.last}"
- `xcrun simctl pair #{watches.last} #{phones.last}`
+ make_phone_watch_pair
end
def self.create(device_type, os_versions, os_name = 'iOS')
os_versions.each do |os_version|
puts "Creating #{device_type} for #{os_name} version #{os_version}"
@@ -57,22 +48,41 @@
def self.filter_runtimes(all_runtimes, os = 'iOS')
all_runtimes.select { |r| r[/^#{os}/] }.map { |r| r.split(' ')[1] }
end
def self.devices
- all_devices = `xcrun simctl list devices`
+ all_devices = Helper.backticks('xcrun simctl list devices', print: $verbose)
# == Devices ==
# -- iOS 9.0 --
# iPhone 4s (32246EBC-33B0-47F9-B7BB-5C23C550DF29) (Shutdown)
# iPhone 5 (4B56C101-6B95-43D1-9485-3FBA0E127FFA) (Shutdown)
# iPhone 5s (6379C204-E82A-4FBD-8A22-6A01C7791D62) (Shutdown)
# -- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-8-4 --
# iPhone 4s (FE9D6F85-1C51-4FE6-8597-FCAB5286B869) (Shutdown) (unavailable, runtime profile not found)
result = all_devices.lines.map do |line|
- (line.match(/\s+([\w\s]+)\s\(([\w\-]+)\)/) || []).to_a
+ (line.match(/\s+(.+?)\s\(([\w\-]+)\).*/) || []).to_a
end
result.select { |parsed| parsed.length == 3 } # we don't care about those headers
+ end
+
+ def self.make_phone_watch_pair
+ phones = []
+ watches = []
+ devices.each do |device|
+ full_line, name, id = device
+ phones << id if name.start_with?('iPhone 6') && device_line_usable?(full_line)
+ watches << id if name.end_with?('mm') && device_line_usable?(full_line)
+ end
+
+ if phones.any? && watches.any?
+ puts "Creating device pair of #{phones.last} and #{watches.last}"
+ Helper.backticks("xcrun simctl pair #{watches.last} #{phones.last}", print: $verbose)
+ end
+ end
+
+ def self.device_line_usable?(line)
+ !line.include?("unavailable")
end
end
end