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

#sim_controlObject (readonly)

Returns the value of attribute sim_control.



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

def sim_control
  @sim_control
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.new.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
# File 'lib/run_loop/cli/simctl.rb', line 55

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

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

  manage_processes
end

#installObject



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/run_loop/cli/simctl.rb', line 165

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



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/run_loop/cli/simctl.rb', line 93

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