refactor: minor nitpicks
This commit is contained in:
33
src/args.rs
Normal file
33
src/args.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(version)]
|
||||
pub struct Args {
|
||||
/// User Agent to use for requests
|
||||
#[arg(
|
||||
short,
|
||||
default_value = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
|
||||
)]
|
||||
pub user_agent: String,
|
||||
|
||||
/// Tags to search for
|
||||
#[arg(short, long, required = true)]
|
||||
pub tags: Vec<String>,
|
||||
|
||||
/// Page to start scraping from
|
||||
#[arg(short, long, default_value_t = 1)]
|
||||
pub page: usize,
|
||||
|
||||
/// Async jobs to use for fetching
|
||||
#[arg(short, long, default_value_t = 4)]
|
||||
pub jobs: usize,
|
||||
|
||||
/// Delay for rate-limits (ms)
|
||||
#[arg(short, long, default_value = "1000", value_parser = parse_duration)]
|
||||
pub delay: std::time::Duration,
|
||||
}
|
||||
|
||||
fn parse_duration(arg: &str) -> Result<std::time::Duration, std::num::ParseIntError> {
|
||||
let seconds = arg.parse()?;
|
||||
Ok(std::time::Duration::from_millis(seconds))
|
||||
}
|
Reference in New Issue
Block a user