1pub mod json;
2pub mod sarif;
3
4use anyhow::Result;
5use libverify_core::assessment::{BatchReport, VerificationResult};
6
7#[derive(Debug, Clone, Copy)]
8pub enum Format {
9 Json,
10 Sarif,
11}
12
13pub struct OutputOptions {
14 pub format: Format,
15 pub only_failures: bool,
16 pub tool_name: String,
18 pub tool_version: String,
20}
21
22pub fn parse_format(s: &str) -> Result<Format> {
23 match s {
24 "json" => Ok(Format::Json),
25 "sarif" => Ok(Format::Sarif),
26 _ => anyhow::bail!("invalid format: {s} (use 'json' or 'sarif')"),
27 }
28}
29
30pub fn render(opts: &OutputOptions, result: &VerificationResult) -> Result<String> {
31 match opts.format {
32 Format::Json => json::render(result, opts.only_failures),
33 Format::Sarif => sarif::render(
34 result,
35 opts.only_failures,
36 &opts.tool_name,
37 &opts.tool_version,
38 ),
39 }
40}
41
42pub fn render_batch(opts: &OutputOptions, batch: &BatchReport) -> Result<String> {
43 match opts.format {
44 Format::Json => json::render_batch(batch, opts.only_failures),
45 Format::Sarif => sarif::render_batch(
46 batch,
47 opts.only_failures,
48 &opts.tool_name,
49 &opts.tool_version,
50 ),
51 }
52}