Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 10, 2024
1 parent 83b6a6b commit 969494f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/cli/clean.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::state_file::{DaemonStatus, StateFile};
use crate::Result;

/// Removes stopped/failed daemons from `pitchfork list`
Expand All @@ -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(())
}
}
2 changes: 1 addition & 1 deletion src/state_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, StateFileDaemon>,
#[serde(skip)]
Expand Down

0 comments on commit 969494f

Please sign in to comment.