1use clap::Parser;
2use std::io::{stdin, Read};
3use std::process;
4
5use dns_types::hosts::types::Hosts;
6use dns_types::zones::types::Zone;
7
8#[derive(Parser)]
10struct Args {
18 #[clap(long, action(clap::ArgAction::SetTrue))]
21 strict: bool,
22}
23
24fn main() {
25 let args = Args::parse();
26
27 let mut buf = String::new();
28 if let Err(err) = stdin().read_to_string(&mut buf) {
29 eprintln!("error reading zone file from stdin: {err:?}");
30 process::exit(1);
31 }
32
33 match Zone::deserialise(&buf) {
34 Ok(zone) => {
35 let try_hosts = if args.strict {
36 Hosts::try_from(zone)
37 } else {
38 Ok(Hosts::from_zone_lossy(&zone))
39 };
40 match try_hosts {
41 Ok(hosts) => print!("{}", hosts.serialise()),
42 Err(err) => {
43 eprintln!("error converting zone file to hosts file: {err:?}");
44 process::exit(1);
45 }
46 }
47 }
48 Err(err) => {
49 eprintln!("error parsing zone file from stdin: {err:?}");
50 process::exit(1);
51 }
52 }
53}