//! `econf` / `easyconf` – configuration validation (named-checkconf). use std::path::PathBuf; use std::process::ExitCode; use clap::{Parser, Subcommand}; use crate::common::*; #[derive(Parser, Debug)] #[command(name = "econf", version = VERSION, about = "EasyConf – validate EasyDNS configuration")] pub struct Args { #[command(subcommand)] pub cmd: Cmd, #[arg(long, global = true)] pub json: bool, } #[derive(Subcommand, Debug)] pub enum Cmd { /// Validate a configuration file (and the zone files it references) Check { file: PathBuf }, /// Print the effective configuration Print { file: PathBuf }, } pub fn main() -> ExitCode { let a = Args::parse(); match a.cmd { Cmd::Check { file } => match dns_config::Config::load(&file) { Ok(cfg) => { let f = dns_server::check::check_config(&cfg); let errors = f.iter().filter(|x| x.severity == "error").count(); if a.json { print_structured(&serde_json::to_value(&f).unwrap_or_default(), false); } else { for x in &f { println!("{x}"); } println!("{}: {}", file.display(), if errors == 0 { "OK" } else { "FAILED" }); } if errors == 0 { ExitCode::SUCCESS } else { ExitCode::from(1) } } Err(e) => fail("econf", 1, e), }, Cmd::Print { file } => match dns_config::Config::load(&file) { Ok(cfg) => { print!("{}", serde_norway::to_string(&cfg).unwrap_or_default()); ExitCode::SUCCESS } Err(e) => fail("econf", 1, e), }, } }