diff --git a/src/commands/download.rs b/src/commands/download.rs index 1b7d164..f85eed4 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -7,7 +7,6 @@ use std::fs::File; use std::fs::{create_dir, rename, write}; use std::io::Write; use std::path::Path; -use std::process::exit; use std::sync::Arc; use tokio::sync::Mutex; use tokio::task::JoinHandle; @@ -19,11 +18,7 @@ const DOWNLOAD_WORKERS: usize = 5; const FAIL_DOWNLOAD_WAIT_TIME: u64 = 5000; pub async fn run(args: env::Args) { - let sauces = utils::get_arg_sauces(args).unwrap(); - if sauces.len() < 1 { - eprintln!("Missing sauce(s)"); - exit(1); - } + let sauces = utils::get_arg_sauces(args); let client = api::get_client(); let mut pages_vec: Vec<(String, String)> = Vec::new(); { diff --git a/src/commands/view.rs b/src/commands/view.rs index 8867127..f240738 100644 --- a/src/commands/view.rs +++ b/src/commands/view.rs @@ -9,11 +9,7 @@ extern crate reqwest; extern crate tokio; pub async fn run(args: env::Args) { - let sauces = utils::get_arg_sauces(args).unwrap(); - if sauces.len() < 1 { - eprintln!("Missing sauce(s)"); - exit(1); - } + let sauces = utils::get_arg_sauces(args); let client = api::get_client(); let mut handles: Vec> = Vec::with_capacity(sauces.len()); diff --git a/src/main.rs b/src/main.rs index 904c5d9..8ff4883 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,6 @@ fn main() { tokio::runtime::Builder::new_multi_thread() .enable_all() .build() - .unwrap() + .expect("failed to build tokio runtime") .block_on(commands::run()); } diff --git a/src/utils.rs b/src/utils.rs index 9d1ee79..805e60e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,17 +1,26 @@ use std::env; -pub fn get_arg_sauces(args: env::Args) -> Result, String> { +use std::process::exit; + +pub fn get_arg_sauces(args: env::Args) -> Vec { let mut sauces: Vec = Vec::new(); + for sauce in args { let sauce: i32 = match sauce.parse() { Ok(sauce) => sauce, Err(_) => { - return Err(format!("{} is not a number/sauce", sauce)); + eprintln!("{} is not a number/sauce", sauce); + exit(1); } }; if !sauces.contains(&sauce) { sauces.push(sauce); } } - Ok(sauces) + + if sauces.len() < 1 { + eprintln!("Missing sauce(s)"); + exit(1); + } + sauces }