Skip to main content

cellos_ctl/cmd/
delete.rs

1//! `cellctl delete formation <name>` — DELETE /v1/formations/<name>.
2
3use std::io::{self, BufRead, Write};
4
5use crate::client::{formation_path, CellosClient};
6use crate::exit::{CtlError, CtlResult};
7
8pub async fn formation(client: &CellosClient, name: &str, assume_yes: bool) -> CtlResult<()> {
9    if !assume_yes {
10        let confirmed = confirm(&format!("Delete formation '{name}'? This is irreversible."))?;
11        if !confirmed {
12            return Err(CtlError::usage("delete cancelled by user"));
13        }
14    }
15    // CTL-002: UUID vs name routing — see `client::formation_path`.
16    client.delete(&formation_path(name)).await?;
17    println!("formation/{name} deleted");
18    Ok(())
19}
20
21fn confirm(prompt: &str) -> CtlResult<bool> {
22    eprint!("{prompt} [y/N] ");
23    io::stderr().flush().ok();
24    let mut line = String::new();
25    io::stdin().lock().read_line(&mut line)?;
26    let trimmed = line.trim().to_ascii_lowercase();
27    Ok(matches!(trimmed.as_str(), "y" | "yes"))
28}