use anyhow::Result;
use std::panic;
fn run() -> Result<()> {
std::env::set_var("RUST_BACKTRACE", "0");
let cli = twars_url2md::cli::Cli::parse_args()?;
let urls = cli.collect_urls()?;
let config = cli.create_config();
let verbose = config.verbose;
let rt = tokio::runtime::Runtime::new()?;
let errors = rt.block_on(twars_url2md::process_urls(urls, config))?;
if !errors.is_empty() && verbose {
eprintln!("\nSummary of failures:");
for (url, error) in &errors {
eprintln!(" {} - {}", url, error);
}
eprintln!("\n{} URLs failed to process", errors.len());
}
Ok(())
}
fn main() {
panic::set_hook(Box::new(|panic_info| {
if let Some(location) = panic_info.location() {
eprintln!(
"Warning: Processing error in {} at line {}: {}",
location.file(),
location.line(),
panic_info
);
} else {
eprintln!("Warning: Processing error occurred: {}", panic_info);
}
}));
let result = panic::catch_unwind(|| {
if let Err(e) = run() {
eprintln!("Error: {}", e);
std::process::exit(1);
}
});
if result.is_err() {
std::process::exit(1);
}
}