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.



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

def simctl
  @simctl
end

Instance Method Details

#bootedObject



35
36
37
38
39
40
41
42
43
# File 'lib/run_loop/cli/simctl.rb', line 35

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/run_loop/cli/simctl.rb', line 60

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

#erase(simulator = nil) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/run_loop/cli/simctl.rb', line 201

def erase(simulator=nil)

  debug = options[:debug]

  RunLoop::Environment.with_debugging(debug) do
    if !simulator
      identifier = RunLoop::Core.default_simulator(xcode)
    else
      identifier = simulator
    end

    options = {simctl: simctl, xcode: xcode}
    device = RunLoop::Device.device_with_identifier(identifier, options)

    RunLoop::CoreSimulator.erase(device, options)
  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

#launch(simulator = nil) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/run_loop/cli/simctl.rb', line 228

def launch(simulator=nil)
  debug = options[:debug]

  RunLoop::Environment.with_debugging(debug) do
    if !simulator
      identifier = RunLoop::Core.default_simulator(xcode)
    else
      identifier = simulator
    end

    options = {simctl: simctl, xcode: xcode}
    device = RunLoop::Device.device_with_identifier(identifier, options)

    core_sim = RunLoop::CoreSimulator.new(device, nil)
    core_sim.launch_simulator
  end
end

#manage_processesObject



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

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

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

  begin
    RunLoop::CoreSimulator.terminate_core_simulator_processes
  ensure
    ENV['DEBUG'] = original_value if debug
  end
end

#tailObject



14
15
16
# File 'lib/run_loop/cli/simctl.rb', line 14

def tail
  tail_simulator_logs
end