aarty/src/main.rs

57 lines
1.5 KiB
Rust
Raw Permalink Normal View History

use clap::Parser;
use image::GenericImageView;
2022-10-03 18:50:48 +00:00
use std::io::Result;
extern crate pretty_env_logger;
2022-10-03 18:13:59 +00:00
#[macro_use]
extern crate log;
2022-10-03 14:04:38 +00:00
mod args;
2022-10-03 18:13:59 +00:00
mod ascii_processor;
mod output;
2022-10-03 14:04:38 +00:00
use crate::args::{args::Arguments, enums::OutputMethod};
2022-10-03 18:13:59 +00:00
use crate::ascii_processor::generate_ascii;
2022-10-03 14:04:38 +00:00
fn main() -> Result<()> {
// Initialize the logger
pretty_env_logger::init();
info!("Successfully initialized logger");
info!("Parsing arguments");
// Parse the arguments
2022-10-03 14:04:38 +00:00
let arguments = Arguments::parse();
info!("Successfully parsed arguments");
trace!("Arguments: {:?}", arguments);
2022-10-03 18:13:59 +00:00
// Validate the arguments
info!("Validating arguments");
match arguments.validate() {
Ok(_) => (),
Err(e) => {
error!("Failed to validate arguments: {}", e);
eprintln!("Failed to validate arguments: {}", e);
std::process::exit(1);
}
}
// Open the image
info!("Opening image: {}", arguments.image);
2022-10-03 18:13:59 +00:00
let image = match image::open(arguments.image.clone()) {
Ok(image) => image,
Err(e) => {
error!("Failed to open image: {:?}", e);
eprintln!("Failed to open image: {:?}", e);
std::process::exit(1);
}
};
info!("Successfully opened image");
trace!("Image dimensions: {:?}", image.dimensions());
generate_ascii(image, &arguments, output::prepare_output(&arguments)?)?;
2022-10-03 18:50:48 +00:00
info!("Successfully processed image");
Ok(())
2022-10-03 11:09:12 +00:00
}