packard/src/main.rs

41 lines
1.2 KiB
Rust
Raw Normal View History

2025-01-14 17:04:14 +00:00
use indicatif::ProgressStyle;
2025-01-13 17:34:24 +00:00
use std::error::Error;
use terminal_link::Link;
use tokio;
2025-01-14 12:32:48 +00:00
mod config;
mod data;
2025-01-14 15:00:12 +00:00
mod utils;
2025-01-13 17:34:24 +00:00
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
2025-01-14 12:32:48 +00:00
let config = config::validate_config();
let args = config::parse_cli();
2025-01-14 15:00:12 +00:00
let (count, skip_amount, list) = config::collate_values(args, &config);
2025-01-13 17:34:24 +00:00
if let Some(values) = config.lists.get(&list) {
2025-01-14 15:32:30 +00:00
let pb = indicatif::ProgressBar::new(
values
.len()
.try_into()
.expect("Could not convert list length"),
);
2025-01-14 17:04:14 +00:00
pb.set_style(ProgressStyle::with_template("{wide_bar} {percent} {msg}").unwrap());
2025-01-14 12:32:48 +00:00
let all_items = data::run_tasks(values.to_vec(), count, skip_amount, &pb).await;
2025-01-13 17:34:24 +00:00
pb.finish_and_clear();
for item in all_items {
println!(
2025-01-14 00:28:35 +00:00
"\x1b[1m>\x1b[0m \x1b[1;32m{}\x1b[0m\n\x1b[3m\x1b[2m{}\x1b[0m\n\x1b[2m{}\x1b[0m\n",
2025-01-13 17:34:24 +00:00
Link::new(&item.title, &item.link),
2025-01-14 15:00:12 +00:00
utils::trim_chars(&item.description),
2025-01-14 00:28:35 +00:00
item.pub_date.to_string()
2025-01-13 17:34:24 +00:00
);
}
} else {
panic!("Have you specified your site lists and chosen one?");
}
Ok(())
}