use crate::MdbClient;
use std::path::PathBuf;
use std::process::ExitCode;
use anyhow::{Context, Result};
use clap::Parser;
#[derive(Parser, Clone, Debug, PartialEq)]
pub struct SampleReport {
pub hash: String,
pub output: Option<PathBuf>,
}
impl SampleReport {
pub async fn exec(&self, config: &MdbClient) -> Result<ExitCode> {
let _bytes = hex::decode(&self.hash).context("Provided hash wasn't valid hexidecimal")?;
let report = config
.report(&self.hash)
.await
.context("failed to get report")?;
if let Some(output) = &self.output {
let report = serde_json::to_string(&report)?;
std::fs::write(output, report).context("failed to write report")?;
} else {
println!("{report}");
}
Ok(ExitCode::SUCCESS)
}
}
#[test]
fn verify_cli() {
use clap::CommandFactory;
SampleReport::command().debug_assert();
}