partiri-cli 0.1.5

partiri CLI — Deploy and manage services on Partiri Cloud
use owo_colors::OwoColorize;
use tabled::Table;

use crate::config::{validate_config, PartiriConfig};
use crate::error::Result;
use crate::output::ValidationRow;

pub fn run(config: &PartiriConfig) -> Result<()> {
    let results = validate_config(config);
    let has_errors = results.iter().any(|r| !r.ok);

    let rows: Vec<ValidationRow> = results
        .iter()
        .map(|r| ValidationRow {
            field: r.field.clone(),
            status: if r.ok {
                "".green().to_string()
            } else {
                "".red().to_string()
            },
            message: if r.ok {
                String::new()
            } else {
                r.message.red().to_string()
            },
        })
        .collect();

    println!("{}", Table::new(rows));

    if has_errors {
        return Err("Config validation failed. Fix the errors above and try again.".into());
    } else {
        println!("\n{} .partiri.jsonc is valid", "".green().bold());
    }

    Ok(())
}