use std::{io, time::Instant};
use clap::Parser;
use owo_colors::OwoColorize;
use crate::{
args::{Args, CleanArgs, Commands},
sanitizer::Sanitizer,
};
mod args;
mod patterns;
mod sanitizer;
use tabled::{
settings::{object::Rows, style::BorderColor, Color, Style},
Table, Tabled,
};
#[derive(Tabled)]
struct ExecutionSummary {
#[tabled(rename = "Metric")]
metric: &'static str,
#[tabled(rename = "Value")]
value: String,
}
fn main() -> io::Result<()> {
let args = Args::parse();
let sanitizer = Sanitizer::new();
match args.commands {
Commands::Clean(CleanArgs { input, output_dir }) => {
println!("{}\n", "Sanitizing files...".blue().bold());
let start_time = Instant::now();
let (processed_files, total_bytes) = sanitizer.sanitize_auto(&input, &output_dir)?;
let elapsed = start_time.elapsed();
let total_mb = total_bytes as f64 / (1024.0 * 1024.0);
let elapsed_secs = elapsed.as_secs_f64();
let throughput_mb_s = if elapsed_secs > 0.0 {
total_mb / elapsed_secs
} else {
0.0
};
let summary_data = vec![
ExecutionSummary {
metric: "Files Processed",
value: processed_files.len().to_string(),
},
ExecutionSummary {
metric: "Total Data",
value: format!("{:.2} MB", total_mb),
},
ExecutionSummary {
metric: "Time Elapsed",
value: format!("{:.3?} ({:.3}s)", elapsed, elapsed_secs),
},
ExecutionSummary {
metric: "Throughput",
value: format!("{:.2} MB/s", throughput_mb_s),
},
];
let mut table = Table::new(summary_data);
table
.with(Style::rounded())
.with(BorderColor::filled(Color::FG_BLUE))
.modify(Rows::new(1..=1), Color::BOLD | Color::FG_GREEN)
.modify(Rows::new(2..=2), Color::FG_YELLOW)
.modify(Rows::new(3..=3), Color::FG_CYAN)
.modify(Rows::new(4..=4), Color::BOLD | Color::FG_MAGENTA);
println!(
"\n\n{}\n\n{}",
"Sanitization Complete!".bold().green(),
table
);
}
}
Ok(())
}