ccdown 0.7.0

A polite and user-friendly downloader for Common Crawl data.
Documentation
use std::process;

use clap::Parser;

use ccdown::cli::Commands;
use ccdown::download;

#[tokio::main]
async fn main() {
    let cli = ccdown::cli::Cli::parse();

    match &cli.command {
        Some(Commands::DownloadPaths {
            snapshot,
            data_type,
            dst,
        }) => {
            let options = download::DownloadOptions {
                snapshot: snapshot.to_string(),
                data_type: data_type.as_str(),
                dst,
                ..Default::default()
            };
            match download::download_paths(options).await {
                Ok(_) => (),
                Err(e) => {
                    eprintln!("Error downloading paths: {}", e);
                }
            };
        }
        Some(Commands::Download {
            path_file,
            dst,
            progress,
            threads,
            retries,
            numbered,
            files_only,
            strict,
        }) => {
            if *numbered && *files_only {
                eprintln!("Numbered and Files Only flags are incompatible");
            } else {
                let options = download::DownloadOptions {
                    paths: path_file,
                    dst,
                    progress: *progress,
                    threads: *threads,
                    max_retries: *retries,
                    numbered: *numbered,
                    files_only: *files_only,
                    strict: *strict,
                    ..Default::default()
                };
                match download::download(options).await {
                    Ok(_) => (),
                    Err(e) => {
                        eprintln!("Error downloading paths: {}", e);
                    }
                };
            }
        }
        Some(Commands::FetchRecord {
            file_path,
            offset,
            output,
            retries,
            max_bytes,
        }) => {
            let options = download::RecordOptions {
                max_bytes: *max_bytes,
                max_retries: *retries,
                base_url: None,
            };
            match download::fetch_record(file_path, *offset, &options).await {
                Ok(record) => {
                    if let Err(e) = std::fs::write(output, &record.body) {
                        eprintln!("Error writing output: {}", e);
                        process::exit(1);
                    }
                }
                Err(e) => {
                    eprintln!("Error fetching record: {}", e);
                    process::exit(1);
                }
            }
        }
        None => {
            eprintln!("No command specified");
        }
    }
}