1use crate::output::{format_human, format_json};
4use crate::OutputFormat;
5use agx::preset::validate::{FileReport, ValidationReport};
6use std::path::PathBuf;
7
8pub fn run_validate(paths: &[PathBuf], quiet: bool, format: OutputFormat) -> i32 {
14 if paths.is_empty() {
15 eprintln!("error: no preset files given");
16 return 2;
17 }
18
19 let file_reports: Vec<FileReport> = paths
20 .iter()
21 .map(|p| agx::preset::Preset::validate(p))
22 .collect();
23
24 let report = ValidationReport::from_files(file_reports);
25
26 let output = match format {
27 OutputFormat::Human => format_human(&report, quiet),
28 OutputFormat::Json => format_json(&report),
29 };
30 print!("{}", output);
31
32 if report.has_errors() {
33 1
34 } else {
35 0
36 }
37}