Initial vid-repair scaffold
This commit is contained in:
10
vid-repair-core/src/report/json.rs
Normal file
10
vid-repair-core/src/report/json.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use anyhow::Result;
|
||||
use serde::Serialize;
|
||||
|
||||
pub fn render_json<T: Serialize>(value: &T, pretty: bool) -> Result<String> {
|
||||
if pretty {
|
||||
Ok(serde_json::to_string_pretty(value)?)
|
||||
} else {
|
||||
Ok(serde_json::to_string(value)?)
|
||||
}
|
||||
}
|
||||
7
vid-repair-core/src/report/mod.rs
Normal file
7
vid-repair-core/src/report/mod.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
mod json;
|
||||
mod text;
|
||||
mod types;
|
||||
|
||||
pub use json::render_json;
|
||||
pub use text::{render_fix_line, render_scan_line, render_summary};
|
||||
pub use types::{Report, ScanReport};
|
||||
54
vid-repair-core/src/report/text.rs
Normal file
54
vid-repair-core/src/report/text.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use crate::fix::FixOutcome;
|
||||
use crate::rules::Severity;
|
||||
use crate::scan::ScanOutcome;
|
||||
|
||||
pub fn render_scan_line(scan: &ScanOutcome) -> String {
|
||||
if scan.issues.is_empty() {
|
||||
format!("[OK] {}", scan.path.display())
|
||||
} else {
|
||||
let max = max_severity(scan);
|
||||
format!(
|
||||
"[ISSUES] {} ({} issues, max {:?})",
|
||||
scan.path.display(),
|
||||
scan.issues.len(),
|
||||
max
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_fix_line(scan: &ScanOutcome, fix: &FixOutcome) -> String {
|
||||
if fix.success {
|
||||
format!("[FIXED] {}", scan.path.display())
|
||||
} else if fix.applied {
|
||||
format!("[FAILED] {} - {}", scan.path.display(), fix.message)
|
||||
} else {
|
||||
format!("[SKIPPED] {} - {}", scan.path.display(), fix.message)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_summary(scans: &[ScanOutcome], fixes: Option<&[FixOutcome]>) -> String {
|
||||
let total = scans.len();
|
||||
let issues = scans.iter().filter(|scan| !scan.issues.is_empty()).count();
|
||||
|
||||
let mut line = format!("Summary: {} files, {} with issues", total, issues);
|
||||
|
||||
if let Some(fixes) = fixes {
|
||||
let fixed = fixes.iter().filter(|fix| fix.success).count();
|
||||
let failed = fixes.iter().filter(|fix| fix.applied && !fix.success).count();
|
||||
let skipped = fixes.iter().filter(|fix| !fix.applied).count();
|
||||
line.push_str(&format!(
|
||||
", {} fixed, {} failed, {} skipped",
|
||||
fixed, failed, skipped
|
||||
));
|
||||
}
|
||||
|
||||
line
|
||||
}
|
||||
|
||||
fn max_severity(scan: &ScanOutcome) -> Severity {
|
||||
scan.issues
|
||||
.iter()
|
||||
.map(|issue| issue.severity)
|
||||
.max_by_key(|sev| sev.rank())
|
||||
.unwrap_or(Severity::Info)
|
||||
}
|
||||
15
vid-repair-core/src/report/types.rs
Normal file
15
vid-repair-core/src/report/types.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::fix::FixOutcome;
|
||||
use crate::scan::ScanOutcome;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ScanReport {
|
||||
pub scan: ScanOutcome,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Report {
|
||||
pub scan: ScanOutcome,
|
||||
pub fix: Option<FixOutcome>,
|
||||
}
|
||||
Reference in New Issue
Block a user