use crate::cli::OutputFormat;
use crate::contracts;
use crate::error::CommandError;
use crate::project;
use crate::tool::{HealthReport, HealthStatus};
pub(crate) fn execute(format: OutputFormat) -> Result<(), CommandError> {
let project = project::discover()?;
let artifact = contracts::load(&project).map_err(CommandError::Contract)?;
let mut report = HealthReport::default();
report.push(
"registry",
HealthStatus::Ok,
format!("{} registered page(s)", artifact.pages.len()),
);
for page in artifact.pages.keys() {
report.push("page", HealthStatus::Ok, page.clone());
}
let hits = contracts::dangerous_fields(&artifact.pages);
for hit in &hits {
report.push(
"lint",
HealthStatus::Error,
format!(
"`{}` exposes field `{}` which matches a secret-bearing name",
hit.page, hit.field
),
);
}
match format {
OutputFormat::Human => report.print_human(),
OutputFormat::Json => report.print_json()?,
}
if report.has_error() {
Err(CommandError::Unhealthy("exposure"))
} else {
Ok(())
}
}