htoz/
main.rs

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