-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtypes.rs
118 lines (103 loc) · 3 KB
/
types.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use crate::error::*;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt::Display};
use strum::{Display as EnumDisplay, EnumString};
use typescript_type_def::TypeDef;
use xcodeproj::pbxproj::PBXTargetInfo;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, Serialize, TypeDef)]
pub struct ProjectInfo {
/// Get watched configurations for given root
pub watchlist: Vec<String>,
/// Get targets information for a registers project with a given root
pub targets: HashMap<String, TargetInfo>,
}
/// Type of operation for building/ruuning a target/scheme
#[derive(Clone, Debug, Serialize, Deserialize, EnumDisplay, EnumString, TypeDef)]
pub enum Operation {
Watch,
Stop,
Once,
}
/// Build Settings used in building/running a target/scheme
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TypeDef)]
pub struct BuildSettings {
/// Target to build
pub target: String,
/// Configuration to build with, default Debug
pub configuration: String,
/// Scheme to build with
pub scheme: Option<String>,
}
/// Target specfic information
#[derive(Clone, Debug, Serialize, Deserialize, TypeDef)]
pub struct TargetInfo {
pub platform: String,
pub configurations: Vec<String>,
}
impl From<PBXTargetInfo> for TargetInfo {
fn from(info: PBXTargetInfo) -> Self {
Self {
platform: info.platform.to_string(),
configurations: info.configurations,
}
}
}
/// Device Lookup information to run built project with
#[derive(Clone, Default, Debug, Serialize, Deserialize, TypeDef)]
pub struct DeviceLookup {
pub name: String,
pub id: String,
}
impl DeviceLookup {
pub fn new(name: String, id: String) -> Self {
Self { name, id }
}
}
impl Default for Operation {
fn default() -> Self {
Self::Once
}
}
impl Display for BuildSettings {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "-configuration {}", self.configuration)?;
if let Some(ref scheme) = self.scheme {
write!(f, " -scheme {scheme}")?;
}
write!(f, " -target {}", self.target)?;
Ok(())
}
}
impl BuildSettings {
pub fn to_args(&self) -> Vec<String> {
self.to_string()
.split_whitespace()
.map(ToString::to_string)
.collect::<Vec<String>>()
}
}
impl Operation {
/// Returns `true` if the request kind is [`Watch`].
///
/// [`Watch`]: RequestKind::Watch
#[must_use]
pub fn is_watch(&self) -> bool {
matches!(self, Self::Watch)
}
/// Returns `true` if the request kind is [`WatchStop`].
///
/// [`WatchStop`]: RequestKind::WatchStop
#[must_use]
#[allow(dead_code)]
pub fn is_stop(&self) -> bool {
matches!(self, Self::Stop)
}
/// Returns `true` if the request kind is [`Once`].
///
/// [`Once`]: RequestKind::Once
#[must_use]
pub fn is_once(&self) -> bool {
matches!(self, Self::Once)
}
}