use adrs_core::{AdrStatus, Repository};
use anyhow::{Context, Result};
use std::path::Path;
pub fn status(
root: &Path,
adr_number: u32,
new_status: &str,
superseded_by: Option<u32>,
) -> Result<()> {
let repo = Repository::open(root).context("Failed to open ADR repository")?;
let status: AdrStatus = new_status.parse().unwrap_or_else(|_| {
AdrStatus::Custom(new_status.to_string())
});
if superseded_by.is_some() && !matches!(status, AdrStatus::Superseded) {
anyhow::bail!("--by can only be used with 'superseded' status");
}
let path = repo
.set_status(adr_number, status.clone(), superseded_by)
.context(format!("Failed to update status for ADR {}", adr_number))?;
match superseded_by {
Some(by) => println!(
"ADR {} status changed to {} (superseded by {})\n {}",
adr_number,
status,
by,
path.display()
),
None => println!(
"ADR {} status changed to {}\n {}",
adr_number,
status,
path.display()
),
}
Ok(())
}