use serde::{Deserialize, Serialize};
use std::str::FromStr;
use derive_is_enum_variant::is_enum_variant;
#[derive(Clone, Debug, Deserialize, Serialize, Hash, PartialEq, Eq, is_enum_variant)]
pub enum PBXTargetPlatform {
#[serde(rename = "iOS")]
IOS,
#[serde(rename = "watchOS")]
WatchOS,
#[serde(rename = "tvOS")]
TvOS,
#[serde(rename = "macOS")]
MacOS,
Unknown,
}
impl Default for PBXTargetPlatform {
fn default() -> Self {
Self::Unknown
}
}
impl PBXTargetPlatform {
pub fn from_sdk_root(sdk_root: &str) -> Self {
match sdk_root {
"iphoneos" => Self::IOS,
"macosx" => Self::MacOS,
"appletvos" => Self::TvOS,
"watchos" => Self::WatchOS,
_ => Self::Unknown,
}
}
pub fn from_identifer(identifer: &str) -> Self {
let name = identifer.replace("com.apple.CoreSimulator.SimRuntime.", "");
let platform_str = name.split("-").next().unwrap().to_string();
match Self::from_str(&platform_str) {
Ok(res) => res,
Err(e) => {
tracing::error!("Platfrom from str: {e}");
Self::Unknown
}
}
}
}
impl FromStr for PBXTargetPlatform {
type Err = String;
fn from_str(s: &str) -> std::result::Result<Self, String> {
match s {
"iOS" => Ok(Self::IOS),
"watchOS" => Ok(Self::WatchOS),
"tvOS" => Ok(Self::TvOS),
"macOS" => Ok(Self::MacOS),
_ => Ok(Self::Unknown),
}
}
}
impl ToString for PBXTargetPlatform {
fn to_string(&self) -> String {
match self {
Self::IOS => "iOS",
Self::WatchOS => "watchOS",
Self::TvOS => "tvOS",
Self::MacOS => "macOS",
_ => "",
}
.into()
}
}