1
use std::path::Path;
2

            
3
use cli_core::CommandError;
4
use rpc::references::{Report, check_references};
5
use sqlx::types::Uuid;
6

            
7
/// Prints the findings and the coverage; any finding fails the run.
8
2
fn conclude(report: &Report) -> Result<(), CommandError> {
9
2
    report.findings().for_each(|finding| println!("{finding}"));
10
2
    report.summary().iter().for_each(|line| println!("{line}"));
11
2
    match report.findings().next() {
12
1
        None => Ok(()),
13
1
        Some(_) => Err(CommandError::Command(
14
1
            "reference preflight failed".to_string(),
15
1
        )),
16
    }
17
2
}
18

            
19
pub async fn run(admin: Uuid, sources: Option<&Path>) -> Result<(), CommandError> {
20
    let report = check_references(admin, sources)
21
        .await
22
        .map_err(|e| CommandError::Command(e.to_string()))?;
23
    conclude(&report)
24
}
25

            
26
#[cfg(test)]
27
mod tests;