From 942558c75200aaad0b4d8561a1f6999f88f843a4 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 12:31:02 +0200 Subject: remove allow too_many_lines and fix them --- src/commands/modification.rs | 114 +++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 58 deletions(-) (limited to 'src/commands/modification.rs') diff --git a/src/commands/modification.rs b/src/commands/modification.rs index aa1174a..8f115ee 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,5 +1,3 @@ -#![allow(clippy::too_many_lines)] - use std::collections::HashMap; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; @@ -114,60 +112,7 @@ pub async fn mod_add( ); for project in projectinfo { - project_p.set_message(format!("Add {}", project.title)); - - let current_version_id = if project.current_version.is_none() { - String::from("NONE") - } else { - project - .current_version - .clone() - .ok_or(MLErr::new(EType::Other, "cur_ver"))? - .id - }; - - match userlist_insert( - config, - &list.id, - &project.mod_id, - ¤t_version_id, - &project.applicable_versions, - &project.download_link, - project.set_version, - ) { - Err(e) => { - let expected_err = format!( - "SQL: UNIQUE constraint failed: {}.mod_id", - list.id - ); - if e.to_string() == expected_err { - Err(MLErr::new( - EType::ModError, - "MOD_ALREADY_ON_SELECTED_LIST", - )) - } else { - Err(e) - } - } - Ok(..) => Ok(..), - }?; - - match mods_insert( - config, - &project.mod_id, - &project.slug, - &project.title, - ) { - Err(e) => { - if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" { - Ok(..) - } else { - Err(e) - } - } - Ok(..) => Ok(..), - }?; - + add_project(config, &project_p, &project, &list)?; if project.current_version.is_some() { downloadstack.push( project @@ -175,8 +120,6 @@ pub async fn mod_add( .ok_or(MLErr::new(EType::Other, "cur_ver"))?, ); }; - - project_p.inc(1); } project_p.finish_with_message("Added all mods to the database"); @@ -199,6 +142,61 @@ pub async fn mod_add( Ok(()) } +fn add_project( + config: &Cfg, + project_p: &ProgressBar, + project: &ProjectInfo, + list: &List, +) -> MLE<()> { + project_p.set_message(format!("Add {}", project.title)); + + let current_version_id = if project.current_version.is_none() { + String::from("NONE") + } else { + project + .current_version + .clone() + .ok_or(MLErr::new(EType::Other, "cur_ver"))? + .id + }; + + match userlist_insert( + config, + &list.id, + &project.mod_id, + ¤t_version_id, + &project.applicable_versions, + &project.download_link, + project.set_version, + ) { + Err(e) => { + let expected_err = + format!("SQL: UNIQUE constraint failed: {}.mod_id", list.id); + if e.to_string() == expected_err { + Err(MLErr::new(EType::ModError, "MOD_ALREADY_ON_SELECTED_LIST")) + } else { + Err(e) + } + } + Ok(..) => Ok(..), + }?; + + match mods_insert(config, &project.mod_id, &project.slug, &project.title) { + Err(e) => { + if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" { + Ok(..) + } else { + Err(e) + } + } + Ok(..) => Ok(..), + }?; + + project_p.inc(1); + + Ok(()) +} + async fn get_mod_infos( config: &Cfg, mod_ids: Vec<(String, bool)>, -- cgit v1.2.3