Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 6, 2024
1 parent 3c219fc commit 054da69
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
4 changes: 4 additions & 0 deletions src/daemon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct Daemon {
pub run: String,
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ mod pid_file;
mod procs;
mod logger;
mod ui;
mod pitchfork_toml;
mod daemon;

pub use eyre::Result;

Expand Down
25 changes: 25 additions & 0 deletions src/pitchfork_toml.rs
Original file line number Diff line number Diff line change
@@ -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<String, Daemon>,
}

impl PitchforkToml {
pub fn read<P: AsRef<Path>>(path: P) -> eyre::Result<Self> {
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<P: AsRef<Path>>(&self, path: P) -> eyre::Result<()> {
let raw = toml::to_string(self)?;
xx::file::write(path, raw)?;
Ok(())
}
}

0 comments on commit 054da69

Please sign in to comment.