Skip to content

Commit

Permalink
Merge pull request #2 from dsully/complete
Browse files Browse the repository at this point in the history
feat: add the remainder of valid fields to Launchd
  • Loading branch information
koenichiwa committed Aug 8, 2023
2 parents 3155984 + 7026537 commit 2639b94
Show file tree
Hide file tree
Showing 11 changed files with 1,073 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ io =["serde", "plist"]
[dependencies]
serde = { version = "1.0", features = ["derive"], optional = true }
plist = { version = "1", optional = true }
cron = { version = "0.9", optional = true }
cron = { version = "0.12", optional = true }
thiserror = "1.0"
10 changes: 10 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt;
use std::ops::RangeInclusive;
use thiserror::Error;

Expand All @@ -20,3 +21,12 @@ pub enum Error {
#[error(transparent)]
Write(plist::Error),
}

// Errors for deserializing Strings into enums that have invalid values.
pub struct EnumDeserializationFromStrError;

impl fmt::Display for EnumDeserializationFromStrError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("EnumDeserializationFromStrError")
}
}
61 changes: 61 additions & 0 deletions src/keep_alive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// See the KeepAlive section in https://www.manpagez.com/man/5/launchd.plist/
//
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(untagged))]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum KeepAliveType {
Enabled(bool),
Options(KeepAliveOptions),
}

impl From<bool> for KeepAliveType {
fn from(value: bool) -> Self {
KeepAliveType::Enabled(value)
}
}

impl From<KeepAliveOptions> for KeepAliveType {
fn from(value: KeepAliveOptions) -> Self {
KeepAliveType::Options(value)
}
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "io", serde(rename_all = "PascalCase"))]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct KeepAliveOptions {
successful_exit: Option<bool>,
network_state: Option<bool>,
path_state: Option<HashMap<String, bool>>,
other_job_enabled: Option<HashMap<String, bool>>,
}

impl KeepAliveOptions {
pub fn new() -> Self {
Self::default()
}

pub fn with_successful_exit(mut self, value: bool) -> Self {
self.successful_exit = Some(value);
self
}

pub fn with_network_state(mut self, value: bool) -> Self {
self.network_state = Some(value);
self
}

pub fn with_path_state(mut self, value: HashMap<String, bool>) -> Self {
self.path_state = Some(value);
self
}

pub fn with_other_job_enabled(mut self, value: HashMap<String, bool>) -> Self {
self.other_job_enabled = Some(value);
self
}
}

0 comments on commit 2639b94

Please sign in to comment.