(
positional: Option<&str>,
global_selector: Option<&str>,
explicit_server_url: Option<&str>,
)
| 3148 | } |
| 3149 | |
| 3150 | fn resolve_cli_device_udid( |
| 3151 | positional: Option<&str>, |
| 3152 | global_selector: Option<&str>, |
| 3153 | explicit_server_url: Option<&str>, |
| 3154 | ) -> anyhow::Result<String> { |
| 3155 | if let Some(udid) = positional.map(str::trim).filter(|value| !value.is_empty()) { |
| 3156 | return Ok(udid.to_owned()); |
| 3157 | } |
| 3158 | |
| 3159 | let selector = global_selector |
| 3160 | .map(str::to_owned) |
| 3161 | .or_else(|| env::var("SIMDECK_DEVICE").ok()) |
| 3162 | .or_else(|| env::var("SIMDECK_UDID").ok()) |
| 3163 | .map(|value| value.trim().to_owned()) |
| 3164 | .filter(|value| !value.is_empty()); |
| 3165 | |
| 3166 | if let Some(selector) = selector { |
| 3167 | if android::is_android_id(&selector) || looks_like_device_selector(&selector) { |
| 3168 | return Ok(selector); |
| 3169 | } |
| 3170 | let server_url = command_service_url(explicit_server_url)?; |
| 3171 | if let Some(simulator) = select_studio_simulator(&server_url, &selector)? { |
| 3172 | return Ok(simulator.udid); |
| 3173 | } |
| 3174 | return Ok(selector); |
| 3175 | } |
| 3176 | |
| 3177 | if let Some(selection) = read_project_device_selection()? { |
| 3178 | let udid = selection.udid.trim(); |
| 3179 | if !udid.is_empty() { |
| 3180 | return Ok(udid.to_owned()); |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | let server_url = command_service_url(explicit_server_url)?; |
| 3185 | if let Some(simulator) = infer_default_cli_simulator(&server_url)? { |
| 3186 | return Ok(simulator.udid); |
| 3187 | } |
| 3188 | |
| 3189 | let simulators = list_studio_simulators(&server_url)?; |
| 3190 | let booted = simulators |
| 3191 | .iter() |
| 3192 | .filter(|simulator| simulator.is_booted) |
| 3193 | .collect::<Vec<_>>(); |
| 3194 | if booted.len() > 1 { |
| 3195 | anyhow::bail!( |
| 3196 | "Multiple booted simulators are available. Pass a UDID, run `simdeck use <UDID>`, use --device, or set SIMDECK_DEVICE." |
| 3197 | ); |
| 3198 | } |
| 3199 | if simulators.is_empty() { |
| 3200 | anyhow::bail!("No simulators are available. Boot one or pass a UDID explicitly."); |
| 3201 | } |
| 3202 | anyhow::bail!( |
| 3203 | "No default simulator could be inferred. Pass a UDID, run `simdeck use <UDID>`, use --device, or set SIMDECK_DEVICE." |
| 3204 | ) |
| 3205 | } |
| 3206 | |
| 3207 | fn infer_default_cli_simulator( |
no test coverage detected