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/update.rs | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src/commands/update.rs') diff --git a/src/commands/update.rs b/src/commands/update.rs index c19c02c..d0b930d 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -1,3 +1,5 @@ +#![allow(clippy::too_many_lines)] + use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use crate::{ @@ -7,7 +9,7 @@ use crate::{ userlist_get_applicable_versions, userlist_get_current_version, userlist_get_set_version, }, - error::{ErrorType, MLError, MLE}, + error::{EType, MLErr, MLE}, files::{ clean_list_dir, delete_version, disable_version, download_versions, }, @@ -15,6 +17,8 @@ use crate::{ List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, }; +/// # Errors +/// # Panics pub async fn update( config: &Cfg, liststack: Vec, @@ -24,11 +28,15 @@ pub async fn update( ) -> MLE<()> { let mp = MultiProgress::new(); - let update_p = - mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); + let update_p = mp.add(ProgressBar::new( + liststack + .len() + .try_into() + .map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?, + )); update_p.set_style( ProgressStyle::with_template(STYLE_BAR_POS) - .unwrap() + .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? .progress_chars(PROGRESS_CHARS), ); @@ -133,16 +141,11 @@ pub async fn update( if delete_old { d_p.set_message(format!("Delete version {}", ver.0)); d_p.inc(1); - delete_version(¤t_list, ver.0)?; + delete_version(¤t_list, &ver.0)?; } else if ver.0 != "NONE" { d_p.set_message(format!("Disable version {}", ver.0)); d_p.inc(1); - disable_version( - config, - current_list.clone(), - ver.0, - ver.1, - )?; + disable_version(config, ¤t_list, ver.0, ver.1)?; }; } @@ -176,12 +179,12 @@ async fn specific_update( let mut versions: Vec = vec![]; - if !applicable_versions.is_empty() { + if applicable_versions.is_empty() { + versions.push(String::from("NONE")); + } else { for ver in &applicable_versions { versions.push(String::from(&ver.id)); } - } else { - versions.push(String::from("NONE")); } let mut current: Vec = vec![]; @@ -189,7 +192,7 @@ async fn specific_update( || (versions.join("|") != userlist_get_applicable_versions( config, - String::from(&list.id), + &list.id, String::from(id), )?) { @@ -209,7 +212,7 @@ async fn specific_update( .ok_or("!no current version in applicable_versions") { Ok(v) => Ok(v), - Err(e) => Err(MLError::new(ErrorType::Other, e)), + Err(e) => Err(MLErr::new(EType::Other, e)), }?; current.push(current_ver.clone()); @@ -223,7 +226,7 @@ async fn specific_update( userlist_change_versions( config, - list.id, + &list.id, current_str, versions.join("|"), link, @@ -232,7 +235,7 @@ async fn specific_update( } if current.is_empty() { - return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE")); + return Err(MLErr::new(EType::ModError, "NO_UPDATE_AVAILABLE")); }; Ok(current[0].clone()) -- cgit v1.2.3