ztoz/
main.rs

1use clap::Parser;
2use std::io::{stdin, Read};
3use std::process;
4
5use dns_types::zones::types::Zone;
6
7// the doc comments for this struct turn into the CLI help text
8#[derive(Parser)]
9/// Read a zone file from stdin, output it in a normalised form to
10/// stdout.
11///
12/// Part of resolved.
13struct Args {}
14
15fn main() {
16    Args::parse();
17
18    let mut buf = String::new();
19    if let Err(err) = stdin().read_to_string(&mut buf) {
20        eprintln!("error reading zone file from stdin: {err:?}");
21        process::exit(1);
22    }
23
24    match Zone::deserialise(&buf) {
25        Ok(zone) => print!("{}", zone.serialise()),
26        Err(err) => {
27            eprintln!("error parsing zone file from stdin: {err:?}");
28            process::exit(1);
29        }
30    }
31}