Class: RunLoop::CLI::Simctl

Inherits:
Thor
  • Object
show all
Defined in:
lib/run_loop/cli/simctl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#simctlObject (readonly)

Returns the value of attribute simctl.



9
10
11
# File 'lib/run_loop/cli/simctl.rb', line 9

def simctl
  @simctl
end

Instance Method Details

#bootedObject



30
31
32
33
34
35
36
37
38
# File 'lib/run_loop/cli/simctl.rb', line 30

def booted
  device = booted_device
  if device.nil?
    version = xcode.version
    puts "No simulator for active Xcode (version #{version}) is booted."
  else
    puts device
  end
end

#doctorObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/run_loop/cli/simctl.rb', line 55

def doctor
  debug = options[:debug]
  device = options[:device]

  manage_processes

  if device
    RunLoop::Environment.with_debugging(debug) do
      RunLoop::CoreSimulator.erase(device)
      launch_simulator(device, xcode)
    end
  else
    RunLoop::Environment.with_debugging(debug) do
      erase_and_launch_each_simulator
    end
  end

end

#installObject



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/run_loop/cli/simctl.rb', line 170

def install
  debug = options[:debug]

  device = expect_device(options)
  app = expect_app(options, device)

  core_sim = RunLoop::CoreSimulator.new(device, app)

  RunLoop::Environment.with_debugging(debug) do
    if options['reset-app-sandbox']

      if core_sim.app_is_installed?
        RunLoop.log_debug('Resetting the app sandbox')
        core_sim.uninstall_app_and_sandbox
      else
        RunLoop.log_debug('App is not installed; skipping sandbox reset')
      end
    end
    core_sim.install
  end
end

#manage_processesObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/run_loop/cli/simctl.rb', line 98

def manage_processes
  debug = options[:debug]
  original_value = ENV['DEBUG']

  ENV['DEBUG'] = '1' if debug

  begin
    RunLoop::CoreSimulator.terminate_core_simulator_processes
    process_name = "com.apple.CoreSimulator.CoreSimulatorService"
    RunLoop::ProcessWaiter.new(process_name).pids.each do |pid|
      kill_options = { :timeout => 0.5 }
      RunLoop::ProcessTerminator.new(pid, 'KILL', process_name, kill_options)
    end
  ensure
    ENV['DEBUG'] = original_value if debug
  end
end

#tailObject



12
13
14
# File 'lib/run_loop/cli/simctl.rb', line 12

def tail
  tail_booted
end