2023-10-28 00:08:10 +00:00
|
|
|
use crate::api;
|
2020-09-12 12:26:07 +00:00
|
|
|
use crate::utils;
|
2020-12-01 15:02:05 +00:00
|
|
|
use crate::structs;
|
2020-09-12 12:26:07 +00:00
|
|
|
|
|
|
|
use std::env;
|
|
|
|
use std::process::exit;
|
|
|
|
use tokio::task::JoinHandle;
|
|
|
|
extern crate tokio;
|
|
|
|
extern crate reqwest;
|
|
|
|
|
|
|
|
pub async fn run(args: env::Args) {
|
|
|
|
let sauces = utils::get_arg_sauces(args).unwrap();
|
2020-12-04 17:08:40 +00:00
|
|
|
if sauces.len() < 1 {
|
2020-09-12 12:26:07 +00:00
|
|
|
eprintln!("Missing sauce(s)");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
let client = reqwest::Client::new();
|
2020-12-02 15:34:42 +00:00
|
|
|
let mut handles: Vec<JoinHandle<(structs::GalleryInfo, i32)>> = Vec::with_capacity(sauces.len());
|
2020-09-12 12:26:07 +00:00
|
|
|
for sauce in sauces {
|
|
|
|
let cloned_client = client.clone();
|
|
|
|
handles.push(tokio::spawn(async move {
|
2023-10-28 00:08:10 +00:00
|
|
|
(api::get_sauce_info(cloned_client, sauce).await.unwrap(), sauce)
|
2020-09-12 12:26:07 +00:00
|
|
|
}));
|
|
|
|
}
|
2020-12-04 01:25:17 +00:00
|
|
|
let mut fail = false;
|
2020-12-04 17:08:40 +00:00
|
|
|
let mut one_done = false;
|
2020-09-12 12:26:07 +00:00
|
|
|
for handle in handles {
|
2020-12-01 17:15:45 +00:00
|
|
|
let (sauce_info, sauce) = handle.await.unwrap();
|
|
|
|
match sauce_info {
|
2020-12-04 17:08:40 +00:00
|
|
|
structs::GalleryInfo::Info(sauce_info) => {
|
|
|
|
if one_done {
|
|
|
|
println!("");
|
|
|
|
}
|
2020-12-20 10:14:55 +00:00
|
|
|
println!("{}", &sauce_info);
|
2020-12-04 17:08:40 +00:00
|
|
|
},
|
2020-12-04 01:25:17 +00:00
|
|
|
structs::GalleryInfo::Error(sauce_error) => {
|
2020-12-04 17:08:40 +00:00
|
|
|
if one_done {
|
|
|
|
eprintln!("");
|
|
|
|
}
|
2020-12-04 01:25:17 +00:00
|
|
|
eprintln!("Sauce: {}\nError: {}", sauce, sauce_error.error);
|
|
|
|
fail = true;
|
|
|
|
}
|
2020-12-01 17:15:45 +00:00
|
|
|
};
|
2020-12-04 17:08:40 +00:00
|
|
|
one_done = true;
|
2020-09-12 12:26:07 +00:00
|
|
|
}
|
2020-12-04 01:25:17 +00:00
|
|
|
if fail {
|
|
|
|
exit(1);
|
|
|
|
}
|
2020-09-12 12:26:07 +00:00
|
|
|
}
|