mod args;
mod color;
mod image_gen;

use anyhow::Result;

use args::{output_path, parse_args};
use color::random_color;
use image_gen::generate_png;

fn main() {
    if let Err(err) = run() {
        eprintln!("Error: {err:#}");
        std::process::exit(1);
    }
}

fn run() -> Result<()> {
    let args = parse_args()?;

    for i in 1..=args.count {
        let color = args.color.unwrap_or_else(random_color);
        let path = output_path(&args.name, i, args.count);
        generate_png(args.width, args.height, &args.name, color, &path)?;
        println!("Generated: {}", path.display());
    }

    Ok(())
}
