Files
EasyDNS/crates/dns-tools/src/conf.rs
T
2026-11-22 14:21:54 +01:00

54 lines
1.7 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! `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),
},
}
}