diff --git a/crates/bough-cli/src/main.rs b/crates/bough-cli/src/main.rs index 7960d9a7..7ba18299 100644 --- a/crates/bough-cli/src/main.rs +++ b/crates/bough-cli/src/main.rs @@ -163,7 +163,15 @@ fn main() { Box::new(render::TendState { added, removed }) } - config::Step::TendWorkspaces => todo!(), + config::Step::TendWorkspaces => { + let mut session = + Session::new(cli.config.clone()).expect("session creation"); + let workers = cli.config.workers as usize; + let workspace_ids = session + .tend_workspaces(workers) + .expect("tend workspaces"); + Box::new(render::TendWorkspaces { workspace_ids }) + } config::Step::InitWorkspace { workspace_id } => todo!(), diff --git a/crates/bough-cli/src/render.rs b/crates/bough-cli/src/render.rs index 2ccf955a..5b7be57d 100644 --- a/crates/bough-cli/src/render.rs +++ b/crates/bough-cli/src/render.rs @@ -396,6 +396,48 @@ impl Render for TendState { } } +pub struct TendWorkspaces { + pub workspace_ids: Vec, +} + +impl Render for TendWorkspaces { + fn markdown(&self) -> String { + let list = self + .workspace_ids + .iter() + .map(|id| format!("- `{id}`")) + .collect::>() + .join("\n"); + format!("# Tend Workspaces\n\n{} total\n\n{list}", self.workspace_ids.len()) + } + + fn terse(&self) -> String { + self.workspace_ids + .iter() + .map(|id| format!("{HASH}{id}{RESET}")) + .collect::>() + .join(" ") + } + + fn verbose(&self) -> String { + let list = self + .workspace_ids + .iter() + .map(|id| format!(" {HASH}{id}{RESET}")) + .collect::>() + .join("\n"); + format!( + "{TITLE}Tend Workspaces{RESET}\n\n{} total\n\n{list}", + self.workspace_ids.len(), + ) + } + + fn json(&self) -> String { + let items: Vec = self.workspace_ids.iter().map(|id| format!("\"{id}\"")).collect(); + format!("[{}]", items.join(",")) + } +} + impl Render for Config { fn markdown(&self) -> String { format!( diff --git a/crates/bough-core/src/lib.rs b/crates/bough-core/src/lib.rs index 549cfc7a..7c694783 100644 --- a/crates/bough-core/src/lib.rs +++ b/crates/bough-core/src/lib.rs @@ -40,3 +40,4 @@ pub use mutation::MutationHash; pub use session::Config; pub use session::Session; pub use state::State; +pub use workspace::WorkspaceId;