From 969494f432886a6399f9823d1568d9418dbacfb0 Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:26:06 +0000 Subject: [PATCH] wip --- src/cli/clean.rs | 7 +++++++ src/state_file.rs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cli/clean.rs b/src/cli/clean.rs index 0513c50..953fa9f 100644 --- a/src/cli/clean.rs +++ b/src/cli/clean.rs @@ -1,3 +1,4 @@ +use crate::state_file::{DaemonStatus, StateFile}; use crate::Result; /// Removes stopped/failed daemons from `pitchfork list` @@ -7,6 +8,12 @@ pub struct Clean {} impl Clean { pub async fn run(&self) -> Result<()> { + let mut sf = StateFile::get().clone(); + let count = sf.daemons.len(); + sf.daemons + .retain(|_, d| matches!(d.status, DaemonStatus::Running | DaemonStatus::Waiting)); + sf.write()?; + println!("Removed {} daemons", count - sf.daemons.len()); Ok(()) } } diff --git a/src/state_file.rs b/src/state_file.rs index 7997c65..5f9e345 100644 --- a/src/state_file.rs +++ b/src/state_file.rs @@ -5,7 +5,7 @@ use std::collections::BTreeMap; use std::fmt::Debug; use std::path::{Path, PathBuf}; -#[derive(Debug, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct StateFile { pub daemons: BTreeMap, #[serde(skip)]