use super::{Context, args};
use crate::boundary::{Action, Gesture};
const AT: &str = "at";
pub(super) fn enroll(tail: &str, ctx: &Context, verb: &str) -> Result<Gesture, String> {
let (words, flags) = args::split_flags(tail);
args::only(&flags, &[AT], verb)?;
let address = args::flag(&flags, AT, verb)?;
let (name, rest) = args::first_word(&words);
if name.is_empty() {
return Err(format!(
"/{verb}: the common name the device's certificate will carry is required — \
/{verb} <common-name> [{}] — bare enrolls a Lernie (operator grade: the seat, \
which reads and steers and hosts its device's tools); add {0} (or thrall) for \
a device that should ONLY offer tools",
crate::registry::peer::FOOT
));
}
let grade = match args::optional_word(&rest, verb)?.as_deref() {
None | Some("lernie") => crate::registry::Grade::default(),
Some("thrall") => crate::registry::Grade::Foot,
Some(word) => crate::boundary::codec::grade_of(word).map_err(|e| {
format!(
"/{verb}: {e} — say thrall or foot for a tools-only device, lernie or \
operator (the bare default) for a seat"
)
})?,
};
Ok(Gesture::Act(Action::Enroll(
crate::registry::enroll::Request {
workspace: args::workspace(ctx, verb)?,
name,
grade,
address,
},
)))
}