htoh/
main.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use clap::Parser;
use std::io::{stdin, Read};
use std::process;

use dns_types::hosts::types::Hosts;

// the doc comments for this struct turn into the CLI help text
#[derive(Parser)]
/// Read a hosts file from stdin, output it in a normalised form to
/// stdout.
///
/// Part of resolved.
struct Args {}

fn main() {
    Args::parse();

    let mut buf = String::new();
    if let Err(err) = stdin().read_to_string(&mut buf) {
        eprintln!("error reading hosts file from stdin: {err:?}");
        process::exit(1);
    }

    match Hosts::deserialise(&buf) {
        Ok(hosts) => print!("{}", hosts.serialise()),
        Err(err) => {
            eprintln!("error parsing hosts file from stdin: {err:?}");
            process::exit(1);
        }
    }
}