use super::{Error, Fx, Outcome};
use crate::template::RealGit;
use crate::workspace::proposal;
use std::path::PathBuf;
#[derive(clap::Args, Debug)]
pub struct Args {
pub workspace: PathBuf,
pub id: Option<String>,
#[arg(long, conflicts_with = "reject")]
pub accept: bool,
#[arg(long)]
pub reject: bool,
}
pub fn run(args: Args, fx: &mut Fx) -> Result<Outcome, Error> {
let e = |source: &dyn std::fmt::Display| Error::new("proposal", source);
if args.accept {
crate::lineage::require_operator(
"accept a proposal onto its lineage",
fx.tool_id.as_deref(),
)
.map_err(|source| e(&source))?;
}
let git = RealGit::new();
let ws = &args.workspace;
let Some(id) = args.id.as_deref() else {
if args.accept || args.reject {
return Err(e(
&"name the proposal to act on: `litany proposal <workspace> <id> --accept|--reject`",
));
}
let rows = proposal::list(ws, &git).map_err(|s| e(&s))?;
return Ok(Outcome::Line(proposal::render(&rows)));
};
crate::name::require_agent_id(id).map_err(|s| e(&s))?;
let product = match (args.accept, args.reject) {
(true, _) => proposal::accept(ws, id, &git),
(_, true) => proposal::reject(ws, id, &git),
_ => proposal::show(ws, id, &git),
};
Ok(Outcome::Line(product.map_err(|s| e(&s))?))
}