rsconstruct 0.7.4

Rust based fast build system
use anyhow::{Context, Result};
use std::path::Path;

use crate::config::IyamllintConfig;
use crate::graph::Product;

pub struct IyamllintProcessor {
    config: IyamllintConfig,
}

impl IyamllintProcessor {
    pub fn new(config: IyamllintConfig) -> Self {
        Self { config }
    }

    fn execute_product(&self, product: &Product) -> Result<()> {
        self.check_files(&[product.primary_input()])
    }

    fn check_files(&self, files: &[&Path]) -> Result<()> {
        let mut errors = Vec::new();

        for file in files {
            let contents = std::fs::read_to_string(file)
                .with_context(|| format!("Failed to read {}", file.display()))?;
            if let Err(e) = serde_yaml::from_str::<serde_yaml::Value>(&contents) {
                errors.push(format!("{}: {}", file.display(), e));
            }
        }

        if errors.is_empty() {
            Ok(())
        } else {
            anyhow::bail!("Invalid YAML:\n{}", errors.join("\n"))
        }
    }
}

impl_checker!(IyamllintProcessor,
    config: config,
    description: "Validate YAML files (in-process)",
    name: crate::processors::names::IYAMLLINT,
    execute: execute_product,
    config_json: true,
    native: true,
    batch: check_files,
);