Skip to content

Commit

Permalink
Plist arrays (BrainiumLLC#74)
Browse files Browse the repository at this point in the history
* Add back missing closing delimiter to `app_dependencies_platform`

* Allow plist-values to be an array

* Move OneOrMany to util

* No longer impl Display for OneOrMany

* Fix warning
  • Loading branch information
ArthurKValladares committed Mar 4, 2022
1 parent cc755c4 commit 20f2d1a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/apple/config/raw.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
apple::teams,
util::{cli::TextWrapper, prompt},
util::{cli::TextWrapper, prompt, OneOrMany},
};
use colored::{Color, Colorize as _};
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display};
use std::fmt::{self, Debug, Display};

#[derive(Debug)]
pub enum DetectError {
Expand Down Expand Up @@ -45,7 +45,7 @@ impl Display for PromptError {
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PListPair {
key: String,
value: String,
value: OneOrMany<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
29 changes: 29 additions & 0 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,32 @@ where
})?;
Ok(result)
}

#[derive(Clone, Debug, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum OneOrMany<T: Debug> {
One(T),
Many(Vec<T>),
}

impl<T: Debug> From<OneOrMany<T>> for Vec<T> {
fn from(from: OneOrMany<T>) -> Self {
match from {
OneOrMany::One(val) => vec![val],
OneOrMany::Many(vec) => vec,
}
}
}

impl<T: Debug> Serialize for OneOrMany<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let serialized_str = match self {
Self::One(one) => format!("{:?}", one),
Self::Many(vec) => format!("{:?}", vec),
};
serializer.serialize_str(&serialized_str)
}
}

0 comments on commit 20f2d1a

Please sign in to comment.