use std::path::{Path, PathBuf};
use std::process::ExitCode;
use blue_lang_runtime::pipeline::{Run, RunError};
use blue_lang_runtime::{Account, Hold};
#[derive(clap::Subcommand)]
pub enum ReceiptCmd {
Verify { file: PathBuf },
}
pub fn run(cmd: ReceiptCmd) -> ExitCode {
match cmd {
ReceiptCmd::Verify { file } => match blue_lang_runtime::receipt::verify(&file) {
Ok(hash) => {
println!("verified {hash}");
ExitCode::SUCCESS
}
Err(e) => {
eprintln!("blue: {e}");
ExitCode::FAILURE
}
},
}
}
pub fn account(receipts: Option<PathBuf>) -> Account {
Account {
identify: Some(blue_lang_mondou::def_hash::identify),
receipts,
..Account::default()
}
}
pub fn hold_for(hold: Option<Hold>, receipts: Option<&Path>) -> Option<Hold> {
match (hold, receipts) {
(None, Some(_)) => Some(Hold::from(blue_lang_waku::Waku::top())),
(hold, _) => hold,
}
}
pub fn write_run(
dir: &Path,
hold: Option<&Hold>,
account: &Account,
outcome: &Result<Run, RunError>,
) {
let Some(hold) = hold else { return };
let receipt = blue_lang_runtime::receipt::of_run(
hold,
account,
blue_lang_runtime::receipt::exit_of(outcome),
);
if let Err(e) = blue_lang_runtime::receipt::write(dir, &receipt) {
eprintln!(
"blue: the run's receipt could not be written to {}: {e}",
dir.display()
);
}
}