simctl/
simctl.rs

1use apple_clis::prelude::*;
2
3fn main() -> Result<(), apple_clis::error::Error> {
4	let xcrun_instance = xcrun::XcRunInstance::new()?;
5	let simctl_instance = xcrun_instance.simctl();
6
7	let output = simctl_instance.list()?;
8	let devices: Vec<&simctl::list::ListDevice> = output.success()?.devices().collect();
9	for device in devices {
10		println!(
11			"Simulator device {name} is {state:?} and is ready = {ready:?}",
12			name = device.name,
13			state = device.state,
14			ready = device.ready()
15		);
16	}
17
18	// the .names() and .ipads() are implemented on extension traits imported with
19	// use apple_clis::prelude::*;
20	// to make finding devices easier and more ergonomic
21	let ipad_simulator: &IPadVariant = output
22		.get_success()
23		.expect("to succeed")
24		.devices()
25		.names()
26		.ipads()
27		.max()
28		.expect("an iPad simulator to be available");
29	println!("Found an {} simulator", ipad_simulator);
30
31	if let IPadVariant::Pro {
32		size, generation, ..
33	} = ipad_simulator
34	{
35		let inches: f32 = size.inches();
36		let gen: u8 = match generation {
37			// generations can be M1 or gen 6
38			Generation::Num(num) => num.get(),	
39			Generation::M(m_gen) => m_gen.get_u8(),
40		};
41		println!(
42			"Ooh, its a pro size {} {:?} generation {} {:?}",
43			size, inches, generation, gen,
44		);
45	}
46
47	// boot the simulator
48	let boot_result = simctl_instance.boot(DeviceName::from(*ipad_simulator))?;
49	match boot_result {
50		simctl::boot::BootOutput::SuccessUnImplemented { .. } => println!("Booted the simulator"),
51		simctl::boot::BootOutput::AlreadyBooted => println!("Simulator was already booted"),
52		_ => println!("PRs welcome to cover more cases"),
53	}
54
55	// open the simulator
56	let open_instance = open::OpenCLIInstance::new()?;
57	open_instance.open_well_known(&open::well_known::WellKnown::Simulator)?;
58
59	Ok(())
60}