From 6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 11:12:04 +0200 Subject: do nearly anything to shut clippy up --- src/commands/modification.rs | 57 +++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'src/commands/modification.rs') diff --git a/src/commands/modification.rs b/src/commands/modification.rs index e0e54b2..6e6213f 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,3 +1,5 @@ +#![allow(clippy::too_many_lines)] + use std::collections::HashMap; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; @@ -9,7 +11,7 @@ use crate::{ mods_remove, userlist_get_all_ids, userlist_get_current_version, userlist_insert, userlist_remove, }, - error::{ErrorType, MLError, MLE}, + error::{EType, MLErr, MLE}, files::{delete_version, download_versions}, modrinth::{ extract_current_version, get_raw_versions, project, projects, versions, @@ -41,6 +43,8 @@ pub struct ProjectInfo { pub set_version: bool, } +/// # Errors +/// # Panics pub async fn mod_add( config: &Cfg, mods: Vec, @@ -52,10 +56,11 @@ pub async fn mod_add( let mut mod_ids: Vec<(String, bool)> = Vec::new(); let mut ver_ids: Vec<(String, bool)> = Vec::new(); - let add_p = mp.add(ProgressBar::new(mods.len().try_into().unwrap())); + let add_p = mp.add(ProgressBar::new(mods.len().try_into().map_err(|_| MLErr::new(EType::Other, "MODSLENTRY"))?)); add_p.set_style( - ProgressStyle::with_template(STYLE_BAR_POS) - .unwrap() + ProgressStyle::with_template(STYLE_BAR_POS).map_err(|_| { + MLErr::new(EType::LibIndicatif, "template error") + })? .progress_chars(PROGRESS_CHARS), ); add_p.set_message("Sort ids"); @@ -83,7 +88,7 @@ pub async fn mod_add( }; if projectinfo.is_empty() { - return Err(MLError::new(ErrorType::ArgumentError, "NO_IDS?")); + return Err(MLErr::new(EType::ArgumentError, "NO_IDS?")); }; add_p.set_message("Add mods to database"); @@ -115,7 +120,7 @@ pub async fn mod_add( &list.id, &project.mod_id, ¤t_version_id, - project.clone().applicable_versions, + &project.applicable_versions, &project.download_link, project.set_version, ) { @@ -125,8 +130,8 @@ pub async fn mod_add( list.id ); if e.to_string() == expected_err { - Err(MLError::new( - ErrorType::ModError, + Err(MLErr::new( + EType::ModError, "MOD_ALREADY_ON_SELECTED_LIST", )) } else { @@ -212,7 +217,20 @@ async fn get_mod_infos( let mut available_versions_vec: Vec = Vec::new(); let current_version: Option; let file: String; - if !available_versions.is_empty() { + if available_versions.is_empty() { + current_version = None; + file = String::from("NONE"); + available_versions_vec.push(String::from("NONE")); + projectinfo.push(ProjectInfo { + mod_id: String::from(&project.id), + slug: project.slug, + title: project.title, + current_version, + applicable_versions: available_versions_vec, + download_link: file, + set_version: *setmap.get(&project.id).unwrap(), + }); + } else { let current_id = extract_current_version(available_versions.clone())?; @@ -246,19 +264,6 @@ async fn get_mod_infos( download_link: file, set_version: *setmap.get(&project.slug).unwrap(), }); - } else { - current_version = None; - file = String::from("NONE"); - available_versions_vec.push(String::from("NONE")); - projectinfo.push(ProjectInfo { - mod_id: String::from(&project.id), - slug: project.slug, - title: project.title, - current_version, - applicable_versions: available_versions_vec, - download_link: file, - set_version: *setmap.get(&project.id).unwrap(), - }); } } @@ -319,9 +324,13 @@ async fn get_ver_info( /// * `config` - config struct /// * `id` - name, slug or id of the mod /// * `list` - List struct +/// +/// # Errors pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { let progress = ProgressBar::new_spinner(); - progress.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + progress.set_style(ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { + MLErr::new(EType::LibIndicatif, "template error") + })?); let mod_id = mods_get_id(&config.data, id)?; @@ -334,7 +343,7 @@ pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { userlist_remove(config, &list.id, &mod_id)?; progress.set_message("Delete file"); - match delete_version(list, version) { + match delete_version(list, &version) { Ok(()) => (), Err(err) => { if err.to_string() -- cgit v1.2.3