use std::{
    io,
    path::{Path, PathBuf},
    process::ExitCode,
};

use clap::Parser;

#[derive(Parser)]
struct Args {
    #[arg(short)]
    parents: bool,
    #[clap(required = true)]
    dirs: Vec<PathBuf>,
}

fn mkdir<P: AsRef<Path>>(path: P, parents: bool) -> Result<(), io::Error> {
    if parents {
        std::fs::create_dir_all(path)
    } else {
        std::fs::create_dir(path)
    }
}

fn main() -> ExitCode {
    let args = Args::parse();
    let mut result = ExitCode::SUCCESS;

    for arg in args.dirs {
        if let Err(e) = mkdir(&arg, args.parents) {
            eprintln!("{}: {}", arg.display(), e);
            result = ExitCode::FAILURE;
        }
    }

    result
}
