use std::{env, fs::OpenOptions, io, path::Path, process::ExitCode};

fn touch<P: AsRef<Path>>(path: P) -> Result<(), io::Error> {
    OpenOptions::new()
        .create(true)
        .write(true)
        .truncate(false)
        .open(path)?;
    Ok(())
}

fn main() -> ExitCode {
    let mut args = env::args();

    if args.len() < 2 {
        eprintln!("Usage: {} FILES", args.next().unwrap());
        return ExitCode::FAILURE;
    }

    let mut result = ExitCode::SUCCESS;

    for arg in args.skip(1) {
        if let Err(err) = touch(&arg) {
            eprintln!("{}: {}", arg, err);
            result = ExitCode::FAILURE;
        }
    }

    result
}
