use super::{Context, args, verbs};
use crate::boundary::{Action, Gesture};
pub(super) fn fan(tail: &str, ctx: &Context, verb: &str) -> Result<Gesture, String> {
let n = args::required(tail, verb, "how many candidates")?;
Ok(Gesture::Act(Action::Fan {
prepared: prepared(ctx, verb)?,
obligation: obligation(ctx, verb)?,
n: n.parse()
.map_err(|_| format!("/{verb}: {n:?} is not a count; usage: /fan <n>"))?,
}))
}
pub(super) fn retire(tail: &str, ctx: &Context, verb: &str) -> Result<Gesture, String> {
Ok(Gesture::Act(Action::Retire {
obligation: obligation(ctx, verb)?,
handle: args::required(tail, verb, "the candidate handle")?,
}))
}
fn obligation(ctx: &Context, verb: &str) -> Result<crate::fan::Obligation, String> {
Ok(crate::fan::Obligation {
project: args::project(ctx, verb)?,
ball: Some(verbs::id("", ctx, verb)?),
})
}
fn prepared(ctx: &Context, verb: &str) -> Result<crate::start::Prepared, String> {
ctx.prepared
.clone()
.ok_or_else(|| format!("/{verb}: nothing is prepared — /prepare first"))
}