apple_clis/xcrun/simctl/
launch.rs1use crate::prelude::*;
2
3use super::XcRunSimctlInstance;
4
5#[cfg(feature = "cli")]
6#[derive(Args, Debug)]
7pub struct CliLaunchArgs {
8 #[clap(long, default_value_t = true)]
9 console: bool,
10
11 #[clap(long)]
12 bundle_id: String,
13
14 #[clap(long, default_value_t = true)]
17 piped: bool,
18}
19
20#[cfg(feature = "cli")]
21impl CliLaunchArgs {
22 pub fn resolve(self) -> Result<(bool, LaunchConfig)> {
23 let config = LaunchConfig {
24 console: self.console,
25 bundle_id: self.bundle_id,
26 };
27 Ok((self.piped, config))
28 }
29}
30
31#[derive(Debug)]
32pub struct LaunchConfig {
33 pub console: bool,
34 pub bundle_id: String,
35}
36
37impl LaunchConfig {
38 pub fn console(&self) -> bool {
39 self.console
40 }
41
42 pub fn bundle_id(&self) -> &str {
43 &self.bundle_id
44 }
45}
46
47pub use output::LaunchOutput;
48mod output;
49
50impl XcRunSimctlInstance<'_> {
51 #[instrument(ret, skip(self,))]
52 pub fn launch(
53 &self,
54 config: &LaunchConfig,
55 simulator_name: DeviceName,
56 ) -> error::Result<LaunchOutput> {
57 let mut cmd = self.bossy_command().with_arg("launch");
58 if config.console() {
59 cmd.add_arg("--console");
60 }
61 cmd.add_arg(simulator_name.to_string());
62 cmd.add_arg(config.bundle_id());
63
64 LaunchOutput::from_bossy_result(cmd.run_and_wait_for_output())
65 }
66
67 #[instrument(skip_all, ret, fields(?config, %simulator_name))]
76 pub fn launch_piped(
77 &self,
78 config: &LaunchConfig,
79 simulator_name: DeviceName,
80 ) -> Result<ExitStatus> {
81 let mut cmd = self.bossy_command().with_arg("launch");
82 if config.console() {
83 cmd.add_arg("--console");
84 } else {
85 warn!(
86 ?config,
87 ?simulator_name,
88 "Why are you calling launch_piped without console set to true?"
89 );
90 }
91 cmd.add_arg(simulator_name.to_string());
92 cmd.add_arg(config.bundle_id());
93
94 Ok(cmd.run_and_wait()?)
95 }
96}