use std::path::PathBuf;
use clap::Args;
use onomancy_core::anchor::doc::DocAnchor;
use onomancy_keyhive::mint::{MintError, document_carriage};
use crate::{say, seed::SeedError};
#[derive(Debug, Args)]
pub(crate) struct Vouch {
#[arg(long, conflicts_with = "doc_key")]
doc_seed: Option<String>,
#[arg(long)]
doc_key: Option<PathBuf>,
#[arg(long, default_value = ".")]
out: PathBuf,
}
impl Vouch {
pub(crate) fn run(&self) -> Result<(), VouchError> {
let doc_key = crate::seed::load(self.doc_seed.as_deref(), self.doc_key.as_deref())
.map_err(|source| VouchError::Seed {
which: "doc key",
source,
})?;
let anchor = DocAnchor::from(doc_key.verifying_key());
let carriage = document_carriage(&doc_key)?;
let mut framed = Vec::new();
carriage.write_framed(&mut framed);
let path = self.out.join(format!("{anchor}.carriage"));
std::fs::write(&path, framed)?;
say(&format!("wrote {}", path.display()));
say(&format!(
"vouches automerge:{anchor} (carriage only — content authorship is not yet checkable)"
));
Ok(())
}
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum VouchError {
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Mint(#[from] MintError),
#[error("{which}: {source}")]
Seed {
which: &'static str,
source: SeedError,
},
}