diff --git a/crates/bough-cli/src/main.rs b/crates/bough-cli/src/main.rs index 67896c9f..7960d9a7 100644 --- a/crates/bough-cli/src/main.rs +++ b/crates/bough-cli/src/main.rs @@ -148,22 +148,37 @@ fn main() { } } - Command::Step { step } => { + Command::Step { ref step } => { debug!(subcommand = ?step, "executing step command"); match step { - config::Step::TendState => todo!(), + config::Step::TendState => { + let mut session = Session::new(cli.config.clone()).expect("session creation"); + let added = session + .tend_add_missing_states() + .expect("tend add missing states"); + let removed = session + .tend_remove_stale_states() + .expect("tend remove stale states"); + Box::new(render::TendState { added, removed }) + } + config::Step::TendWorkspaces => todo!(), + config::Step::InitWorkspace { workspace_id } => todo!(), + config::Step::ResetWorkspace { workspace_id } => todo!(), + config::Step::ApplyMutation { workspace_id, mutation_hash, } => todo!(), + config::Step::UnapplyMutation { workspace_id, mutation_hash, } => todo!(), + config::Step::TestMutation { workspace_id, mutation_hash, diff --git a/crates/bough-cli/src/render.rs b/crates/bough-cli/src/render.rs index 0ffbd68e..2ccf955a 100644 --- a/crates/bough-cli/src/render.rs +++ b/crates/bough-cli/src/render.rs @@ -349,6 +349,53 @@ impl Render for SingleMutation { } } +pub struct TendState { + pub added: Vec, + pub removed: Vec, +} + +fn hash_list_json(hashes: &[bough_core::MutationHash]) -> String { + let items: Vec = hashes.iter().map(|h| format!("\"{h}\"")).collect(); + format!("[{}]", items.join(",")) +} + +impl Render for TendState { + fn markdown(&self) -> String { + format!( + "# Tend State\n\n- Added: {}\n- Removed: {}", + self.added.len(), + self.removed.len(), + ) + } + + fn terse(&self) -> String { + format!("+{} -{}", self.added.len(), self.removed.len()) + } + + fn verbose(&self) -> String { + let mut out = format!( + "{TITLE}Tend State{RESET}\n\nAdded: {}, Removed: {}", + self.added.len(), + self.removed.len(), + ); + for h in &self.added { + out.push_str(&format!("\n {HASH}+{h}{RESET}")); + } + for h in &self.removed { + out.push_str(&format!("\n {HASH}-{h}{RESET}")); + } + out + } + + fn json(&self) -> String { + format!( + r#"{{"added":{},"removed":{}}}"#, + hash_list_json(&self.added), + hash_list_json(&self.removed), + ) + } +} + impl Render for Config { fn markdown(&self) -> String { format!(