Class: Snapshot::ResetSimulators

Inherits:
Object
  • Object
show all
Defined in:
lib/snapshot/reset_simulators.rb

Class Method Summary collapse

Class Method Details

.clear_everything!(ios_version) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/snapshot/reset_simulators.rb', line 3

def self.clear_everything!(ios_version)
  # Taken from https://gist.github.com/cabeca/cbaacbeb6a1cc4683aa5

  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  # !! Warning: This script will remove all your existing simulators !!
  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  sure = true if ENV["SNAPSHOT_FORCE_DELETE"]
  sure = agree("Are you sure? All your simulators will be DELETED and new ones will be created! (y/n)".red, true) unless sure

  raise "User cancelled action" unless sure
   
  device_types_output = `xcrun simctl list devicetypes`
  device_types = device_types_output.scan /(.*) \((.*)\)/
   
  devices_output = `xcrun simctl list devices`.split("\n")

  devices_output.each do |line|
    device = line.match(/\s+([\w\s]+)\(([\w\-]+)\)/)
    if device and device.length == 3
      name = device[1].strip
      id = device[2]
      puts "Removing device #{name} (#{id})"
      `xcrun simctl delete #{id}`
    end
  end

  device_types.each do |device_type|
    puts "Creating #{device_type} for iOS version #{ios_version}"
    command = "xcrun simctl create '#{device_type[0]}' #{device_type[1]} #{ios_version}"
    command_output = `#{command}`
  end
end