mod metrics;
mod network;
mod options;
mod report;
mod sitemap;
mod storage;
mod utils;
use std::error::Error;
use std::process::ExitCode;
use std::sync::Arc;
use crate::sitemap::{fetch_and_generate_report, get_sitemap_urls};
use clap::Parser;
use console::style;
use tokio::time::Instant;
#[tokio::main]
async fn main() -> Result<ExitCode, Box<dyn Error>> {
let options = options::Cli::parse();
let client = Arc::new(network::build_client(&options)?);
let start_time = Instant::now();
let urls = get_sitemap_urls(options.sitemap_url.as_str(), &client)
.await
.map_err(|e| {
eprintln!("{} {}", style("[ERROR]").red(), e);
std::process::exit(1);
})?;
let report = fetch_and_generate_report(urls, &client, &options, &start_time).await?;
report.show_text_report(&options);
if let Some(path) = options.report_path.as_ref() {
report.write_csv_report(path)?;
}
if let Some(path) = options.report_path_json.as_ref() {
report.write_json_report(&options, path)?;
}
Ok(ExitCode::SUCCESS)
}