pub mod schemas;
#[cfg(feature = "widgets")]
pub mod widgets;
pub fn resolve_id_prefix<I>(
input: &str,
candidates: I,
) -> anyhow::Result<triblespace::core::id::Id>
where
I: IntoIterator<Item = triblespace::core::id::Id>,
{
use anyhow::bail;
use triblespace::core::id::Id;
let trimmed = input.trim().to_ascii_lowercase();
if trimmed.is_empty() {
bail!("empty id");
}
if trimmed.len() == 32 {
return Id::from_hex(&trimmed).ok_or_else(|| anyhow::anyhow!("invalid id '{trimmed}'"));
}
let mut matches: std::collections::HashSet<Id> = std::collections::HashSet::new();
for id in candidates {
if format!("{id:x}").starts_with(&trimmed) {
matches.insert(id);
}
}
match matches.len() {
0 => bail!("no id starts with '{trimmed}'"),
1 => Ok(matches.into_iter().next().unwrap()),
n => bail!("{n} matches for prefix '{trimmed}'; provide a longer prefix"),
}
}