use crate::nav::convs::Conversation;
use std::path::{Path, PathBuf};
pub mod agent;
mod exec;
pub use exec::{DELETE_STEP, DeleteError, execute};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Claim {
pub project: PathBuf,
pub id: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Confirmation {
pub name: String,
pub workspace: PathBuf,
pub conversations: Vec<String>,
pub live: Vec<String>,
pub claims: Vec<Claim>,
}
impl Confirmation {
pub fn ball_ids(&self) -> Vec<String> {
self.claims.iter().map(|c| c.id.clone()).collect()
}
pub fn refused(&self) -> bool {
!self.live.is_empty()
}
pub fn armed(&self, typed: &str) -> bool {
!self.refused() && crate::names::normalize(typed) == self.name
}
}
pub fn confirmation(
name: &str,
workspace: &Path,
convs: &[Conversation],
claims: Vec<Claim>,
) -> Confirmation {
Confirmation {
name: name.to_owned(),
workspace: workspace.to_path_buf(),
conversations: convs.iter().map(|c| c.name.clone()).collect(),
live: convs
.iter()
.filter(|c| c.live)
.map(|c| c.name.clone())
.collect(),
claims,
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Step {
Release {
project: PathBuf,
id: String,
name: String,
},
Prune { key: String },
Remove { workspace: PathBuf, wall: PathBuf },
}
pub fn plan(confirm: &Confirmation, world_root: &Path) -> Vec<Step> {
let mut steps: Vec<Step> = confirm
.claims
.iter()
.map(|c| Step::Release {
project: c.project.clone(),
id: c.id.clone(),
name: confirm.name.clone(),
})
.collect();
steps.push(Step::Prune {
key: crate::nav::ws_key(&confirm.workspace),
});
steps.push(Step::Remove {
workspace: confirm.workspace.clone(),
wall: crate::world::wall::root_under(world_root, &confirm.name),
});
steps
}
#[cfg(test)]
mod tests;