Move more sauce common code into get_arg_sauces
This commit is contained in:
parent
1d8210967c
commit
841d740475
|
@ -7,7 +7,6 @@ use std::fs::File;
|
||||||
use std::fs::{create_dir, rename, write};
|
use std::fs::{create_dir, rename, write};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::exit;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
|
@ -19,11 +18,7 @@ const DOWNLOAD_WORKERS: usize = 5;
|
||||||
const FAIL_DOWNLOAD_WAIT_TIME: u64 = 5000;
|
const FAIL_DOWNLOAD_WAIT_TIME: u64 = 5000;
|
||||||
|
|
||||||
pub async fn run(args: env::Args) {
|
pub async fn run(args: env::Args) {
|
||||||
let sauces = utils::get_arg_sauces(args).unwrap();
|
let sauces = utils::get_arg_sauces(args);
|
||||||
if sauces.len() < 1 {
|
|
||||||
eprintln!("Missing sauce(s)");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
let client = api::get_client();
|
let client = api::get_client();
|
||||||
let mut pages_vec: Vec<(String, String)> = Vec::new();
|
let mut pages_vec: Vec<(String, String)> = Vec::new();
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,11 +9,7 @@ extern crate reqwest;
|
||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
|
|
||||||
pub async fn run(args: env::Args) {
|
pub async fn run(args: env::Args) {
|
||||||
let sauces = utils::get_arg_sauces(args).unwrap();
|
let sauces = utils::get_arg_sauces(args);
|
||||||
if sauces.len() < 1 {
|
|
||||||
eprintln!("Missing sauce(s)");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
let client = api::get_client();
|
let client = api::get_client();
|
||||||
let mut handles: Vec<JoinHandle<(structs::GalleryInfo, i32)>> =
|
let mut handles: Vec<JoinHandle<(structs::GalleryInfo, i32)>> =
|
||||||
Vec::with_capacity(sauces.len());
|
Vec::with_capacity(sauces.len());
|
||||||
|
|
|
@ -9,6 +9,6 @@ fn main() {
|
||||||
tokio::runtime::Builder::new_multi_thread()
|
tokio::runtime::Builder::new_multi_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.expect("failed to build tokio runtime")
|
||||||
.block_on(commands::run());
|
.block_on(commands::run());
|
||||||
}
|
}
|
||||||
|
|
15
src/utils.rs
15
src/utils.rs
|
@ -1,17 +1,26 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
pub fn get_arg_sauces(args: env::Args) -> Result<Vec<i32>, String> {
|
use std::process::exit;
|
||||||
|
|
||||||
|
pub fn get_arg_sauces(args: env::Args) -> Vec<i32> {
|
||||||
let mut sauces: Vec<i32> = Vec::new();
|
let mut sauces: Vec<i32> = Vec::new();
|
||||||
|
|
||||||
for sauce in args {
|
for sauce in args {
|
||||||
let sauce: i32 = match sauce.parse() {
|
let sauce: i32 = match sauce.parse() {
|
||||||
Ok(sauce) => sauce,
|
Ok(sauce) => sauce,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
return Err(format!("{} is not a number/sauce", sauce));
|
eprintln!("{} is not a number/sauce", sauce);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if !sauces.contains(&sauce) {
|
if !sauces.contains(&sauce) {
|
||||||
sauces.push(sauce);
|
sauces.push(sauce);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(sauces)
|
|
||||||
|
if sauces.len() < 1 {
|
||||||
|
eprintln!("Missing sauce(s)");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
sauces
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue