From 054da697293914226cd97dd60a2f330a1c78ed7e Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:57:18 +0000 Subject: [PATCH] wip --- Cargo.lock | 3 +++ Cargo.toml | 3 ++- src/daemon.rs | 4 ++++ src/main.rs | 2 ++ src/pitchfork_toml.rs | 25 +++++++++++++++++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/daemon.rs create mode 100644 src/pitchfork_toml.rs diff --git a/Cargo.lock b/Cargo.lock index 9504eb0..a3fa31f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -409,6 +409,7 @@ checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown", + "serde", ] [[package]] @@ -639,6 +640,7 @@ dependencies = [ "console", "dirs", "eyre", + "indexmap", "interprocess", "log", "once_cell", @@ -950,6 +952,7 @@ version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ + "indexmap", "serde", "serde_spanned", "toml_datetime", diff --git a/Cargo.toml b/Cargo.toml index 25c6141..0efce0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,5 +21,6 @@ interprocess = { version = "2.2.2", features = ["tokio"] } tokio = { version = "1.42.0", features = ["full"] } sysinfo = "0.33.0" serde = { version = "1.0.215", features = ["derive"] } -toml = "0.8.19" +toml = { version = "0.8.19", features = ["indexmap", "preserve_order"] } console = "0.15.8" +indexmap = { version = "2.7.0", features = ["serde"] } diff --git a/src/daemon.rs b/src/daemon.rs new file mode 100644 index 0000000..d15f79c --- /dev/null +++ b/src/daemon.rs @@ -0,0 +1,4 @@ +#[derive(Debug, serde::Serialize, serde::Deserialize)] +pub struct Daemon { + pub run: String, +} diff --git a/src/main.rs b/src/main.rs index e2eff26..5eed6b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,8 @@ mod pid_file; mod procs; mod logger; mod ui; +mod pitchfork_toml; +mod daemon; pub use eyre::Result; diff --git a/src/pitchfork_toml.rs b/src/pitchfork_toml.rs new file mode 100644 index 0000000..5005274 --- /dev/null +++ b/src/pitchfork_toml.rs @@ -0,0 +1,25 @@ +use std::path::Path; +use indexmap::IndexMap; +use crate::daemon::Daemon; + +#[derive(Debug, Default, serde::Serialize, serde::Deserialize)] +pub struct PitchforkToml { + pub daemons: IndexMap, +} + +impl PitchforkToml { + pub fn read>(path: P) -> eyre::Result { + if !path.as_ref().exists() { + return Ok(Self::default()); + } + let raw = xx::file::read_to_string(path)?; + let pids = toml::from_str(&raw)?; + Ok(pids) + } + + pub fn write>(&self, path: P) -> eyre::Result<()> { + let raw = toml::to_string(self)?; + xx::file::write(path, raw)?; + Ok(()) + } +}