Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod storage;

use output::OutputFormat;
use rules::RulesFile;
use runner::run_rule;
use runner::{fetch_violation_samples, run_rule};
use storage::register_data;

use crate::{
Expand All @@ -35,6 +35,9 @@ struct Cli {
/// Print full error chain on failure
#[arg(long)]
verbose: bool,
/// Show first N violating rows per failed rule (default 5)
#[arg(long, value_name = "N", default_missing_value = "5", num_args = 0..=1)]
show_violations: Option<u64>,
}

#[tokio::main]
Expand Down Expand Up @@ -102,11 +105,19 @@ async fn run(args: Cli) -> anyhow::Result<()> {
}
let mut results: Vec<RuleResult> = Vec::new();
for rule in &rules.rules {
let result = run_rule(&ctx, rule, total_rows)
let mut result = run_rule(&ctx, rule, total_rows)
.await
.with_context(|| format!("Rule '{}' failed to execute", rule.name))?;
if matches!(result.status, RuleStatus::Fail) {
any_failed = true;
if let Some(limit) = args.show_violations {
let samples = fetch_violation_samples(&ctx, rule, limit)
.await
.with_context(|| {
format!("Failed to fetch violation samples for rule '{}'", rule.name)
})?;
result.sample_rows = Some(samples);
}
}
results.push(result);
}
Expand Down
65 changes: 57 additions & 8 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,65 @@ pub fn build_json(results: &[RuleResult]) -> String {
}

pub fn build_table(results: &[RuleResult]) -> String {
let has_samples = results
.iter()
.any(|r| r.sample_rows.as_ref().is_some_and(|s| !s.is_empty()));

let mut table = Table::new();
table.set_header(["RULE", "STATUS", "VIOLATIONS", "TOTAL", "RATE"]);
results.iter().for_each(|res| {
table.add_row([
res.name.clone(),
format!("{}", res.status),
res.violations.to_string(),
res.total_rows.to_string(),
format!("{:.1}%", res.violation_rate * 100.0),
if has_samples {
table.set_header([
"RULE",
"STATUS",
"VIOLATIONS",
"TOTAL",
"RATE",
"SAMPLE VIOLATIONS",
]);
} else {
table.set_header(["RULE", "STATUS", "VIOLATIONS", "TOTAL", "RATE"]);
}
results.iter().for_each(|res| {
if has_samples {
let sample_str = match &res.sample_rows {
Some(rows) if !rows.is_empty() => {
let parts: Vec<String> = rows
.iter()
.map(|row| {
// Render each row as compact JSON; truncate long values
let s = serde_json::to_string(row).unwrap_or_default();
if s.len() > 60 {
format!("{}…", &s[..60])
} else {
s
}
})
.collect();
let joined = parts.join(", ");
if joined.len() > 120 {
format!("{}…", &joined[..120])
} else {
joined
}
}
_ => String::new(),
};
table.add_row([
res.name.clone(),
format!("{}", res.status),
res.violations.to_string(),
res.total_rows.to_string(),
format!("{:.1}%", res.violation_rate * 100.0),
sample_str,
]);
} else {
table.add_row([
res.name.clone(),
format!("{}", res.status),
res.violations.to_string(),
res.total_rows.to_string(),
format!("{:.1}%", res.violation_rate * 100.0),
]);
}
});
table.to_string()
}
Loading
Loading