use std::error::Error;

use argh::FromArgs;

use crate::parsing::HostsFile;

/// Format the hosts file
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "format")]
pub struct Args {}

pub fn main(_: &Args) -> Result<(), Box<dyn Error>> {
    let mut hosts_file = HostsFile::load();

    let result = hosts_file.write();
    if result.is_err() {
        return Err(From::from(result.err().unwrap()));
    }

    Ok(())
}
