From c7ecf3019a75dc0ab1a0aefeb9b880899fc8a231 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 29 May 2023 18:01:12 +0200 Subject: cargo fmt and add fmt file --- src/commands/download.rs | 39 ++++++++++++++++++++---------- src/commands/io.rs | 6 ++++- src/commands/list.rs | 4 ++-- src/commands/modification.rs | 55 +++++++++++++++++++++++++++++++++---------- src/commands/update.rs | 56 ++++++++++++++++++++++++++++++++++---------- 5 files changed, 121 insertions(+), 39 deletions(-) (limited to 'src/commands') diff --git a/src/commands/download.rs b/src/commands/download.rs index dd00ffb..a7cf744 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -5,7 +5,8 @@ use crate::{ db::userlist_get_all_current_versions_with_mods, error::{ErrorType, MLError, MLE}, files::{ - clean_list_dir, delete_version, disable_version, download_versions, get_downloaded_versions, + clean_list_dir, delete_version, disable_version, download_versions, + get_downloaded_versions, }, modrinth::get_raw_versions, }; @@ -18,7 +19,8 @@ pub async fn download( delete_old: bool, ) -> MLE<()> { let mp = MultiProgress::new(); - let download_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); + let download_p = + mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); download_p.set_style( ProgressStyle::with_template(STYLE_BAR_POS) .unwrap() @@ -28,14 +30,19 @@ pub async fn download( for current_list in liststack { download_p.set_message(format!("Download in {}", current_list.id)); - let downloaded_versions = get_downloaded_versions(current_list.clone())?; - let current_version_ids = match userlist_get_all_current_versions_with_mods( - config, - String::from(¤t_list.id), - ) { - Ok(i) => Ok(i), - Err(e) => Err(MLError::new(ErrorType::DBError, e.to_string().as_str())), - }?; + let downloaded_versions = + get_downloaded_versions(current_list.clone())?; + let current_version_ids = + match userlist_get_all_current_versions_with_mods( + config, + String::from(¤t_list.id), + ) { + Ok(i) => Ok(i), + Err(e) => Err(MLError::new( + ErrorType::DBError, + e.to_string().as_str(), + )), + }?; let mut to_download: Vec = vec![]; //(mod_id, version_id) @@ -54,7 +61,10 @@ pub async fn download( .ok_or("SOMETHING_HAS_REALLY_GONE_WRONG") .unwrap(); if ¤t_version != downloaded_version { - to_disable.push((mod_id.clone(), String::from(downloaded_version))); + to_disable.push(( + mod_id.clone(), + String::from(downloaded_version), + )); to_download.push(current_version); } } @@ -98,7 +108,12 @@ pub async fn download( } else { d_p.set_message(format!("Disable version {}", ver.1)); d_p.inc(1); - disable_version(config, current_list.clone(), ver.1, ver.0)?; + disable_version( + config, + current_list.clone(), + ver.1, + ver.0, + )?; }; } diff --git a/src/commands/io.rs b/src/commands/io.rs index 2501583..8e44b2b 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -102,7 +102,11 @@ pub fn export(config: &Cfg, list: Option) -> MLE<()> { Ok(()) } -pub async fn import(config: &Cfg, file_str: &str, direct_download: bool) -> MLE<()> { +pub async fn import( + config: &Cfg, + file_str: &str, + direct_download: bool, +) -> MLE<()> { let mut file = File::open(file_str)?; let mut content = String::new(); file.read_to_string(&mut content)?; diff --git a/src/commands/list.rs b/src/commands/list.rs index b0a082d..3665446 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -3,8 +3,8 @@ use indicatif::{ProgressBar, ProgressStyle}; use crate::{ config::Cfg, db::{ - config_change_current_list, config_get_current_list, lists_get, lists_get_all_ids, - lists_insert, lists_remove, lists_version, + config_change_current_list, config_get_current_list, lists_get, + lists_get_all_ids, lists_insert, lists_remove, lists_version, }, error::{ErrorType, MLError, MLE}, update, Modloader, STYLE_OPERATION, diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 577bbd1..4488b70 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -5,12 +5,16 @@ use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use crate::{ config::Cfg, db::{ - lists_get_all_ids, mods_get_id, mods_get_info, mods_insert, mods_remove, - userlist_get_all_ids, userlist_get_current_version, userlist_insert, userlist_remove, + lists_get_all_ids, mods_get_id, mods_get_info, mods_insert, + mods_remove, userlist_get_all_ids, userlist_get_current_version, + userlist_insert, userlist_remove, }, error::{ErrorType, MLError, MLE}, files::{delete_version, download_versions}, - modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, + modrinth::{ + extract_current_version, get_raw_versions, project, projects, versions, + Version, + }, List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, }; @@ -60,7 +64,9 @@ pub async fn mod_add( for m in mods { add_p.inc(1); match m.id { - IDSelector::ModificationID(pid) => mod_ids.push((pid, m.set_version)), + IDSelector::ModificationID(pid) => { + mod_ids.push((pid, m.set_version)) + } IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), } } @@ -69,7 +75,8 @@ pub async fn mod_add( let mut projectinfo: Vec = Vec::new(); if !mod_ids.is_empty() { - projectinfo.append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); + projectinfo + .append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); }; if !ver_ids.is_empty() { projectinfo.append(&mut get_ver_info(config, ver_ids).await?); @@ -113,7 +120,10 @@ pub async fn mod_add( project.set_version, ) { Err(e) => { - let expected_err = format!("SQL: UNIQUE constraint failed: {}.mod_id", list.id); + let expected_err = format!( + "SQL: UNIQUE constraint failed: {}.mod_id", + list.id + ); if e.to_string() == expected_err { Err(MLError::new( ErrorType::ModError, @@ -126,7 +136,12 @@ pub async fn mod_add( Ok(..) => Ok(..), }?; - match mods_insert(config, &project.mod_id, &project.slug, &project.title) { + match mods_insert( + config, + &project.mod_id, + &project.slug, + &project.title, + ) { Err(e) => { if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" { Ok(..) @@ -149,7 +164,14 @@ pub async fn mod_add( //Download all the added mods if direct_download { add_p.set_message("Download mods"); - download_versions(list.clone(), config.clone(), downloadstack, &mp, &add_p).await?; + download_versions( + list.clone(), + config.clone(), + downloadstack, + &mp, + &add_p, + ) + .await?; }; add_p.finish_with_message("Added all mods"); @@ -191,7 +213,8 @@ async fn get_mod_infos( let current_version: Option; let file: String; if !available_versions.is_empty() { - let current_id = extract_current_version(available_versions.clone())?; + let current_id = + extract_current_version(available_versions.clone())?; current_version = Some( available_versions @@ -242,7 +265,10 @@ async fn get_mod_infos( Ok(projectinfo) } -async fn get_ver_info(config: &Cfg, ver_ids: Vec<(String, bool)>) -> MLE> { +async fn get_ver_info( + config: &Cfg, + ver_ids: Vec<(String, bool)>, +) -> MLE> { let mut setmap: HashMap = HashMap::new(); let mut ids = vec![]; @@ -311,7 +337,9 @@ pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { match delete_version(list, version) { Ok(_) => (), Err(err) => { - if err.to_string() != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" { + if err.to_string() + != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" + { return Err(err); }; } @@ -343,7 +371,10 @@ pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { mods_remove(config, &mod_id)?; }; - progress.finish_with_message(format!("Removed {} from {}", info.title, list.id)); + progress.finish_with_message(format!( + "Removed {} from {}", + info.title, list.id + )); Ok(()) } diff --git a/src/commands/update.rs b/src/commands/update.rs index 3aae002..c19c02c 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -4,10 +4,13 @@ use crate::{ config::Cfg, db::{ mods_get_info, userlist_change_versions, userlist_get_all_ids, - userlist_get_applicable_versions, userlist_get_current_version, userlist_get_set_version, + userlist_get_applicable_versions, userlist_get_current_version, + userlist_get_set_version, }, error::{ErrorType, MLError, MLE}, - files::{clean_list_dir, delete_version, disable_version, download_versions}, + files::{ + clean_list_dir, delete_version, disable_version, download_versions, + }, modrinth::{extract_current_version, versions, Version}, List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, }; @@ -21,7 +24,8 @@ 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().unwrap())); update_p.set_style( ProgressStyle::with_template(STYLE_BAR_POS) .unwrap() @@ -32,12 +36,16 @@ pub async fn update( update_p.set_message(format!("Update {}", current_list.id)); let list_p = mp.insert_before(&update_p, ProgressBar::new(2)); - list_p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + list_p + .set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); list_p.set_message("Update mods"); let mods = userlist_get_all_ids(config, ¤t_list.id)?; - let list_u_p = mp.insert_before(&list_p, ProgressBar::new(mods.len().try_into().unwrap())); + let list_u_p = mp.insert_before( + &list_p, + ProgressBar::new(mods.len().try_into().unwrap()), + ); list_u_p.set_style( ProgressStyle::with_template(STYLE_BAR_POS) .unwrap() @@ -58,10 +66,19 @@ pub async fn update( } //Getting current installed version for disable or delete - let disable_version = userlist_get_current_version(config, ¤t_list.id, &id)?; + let disable_version = + userlist_get_current_version(config, ¤t_list.id, &id)?; updatestack.push( - match specific_update(config, clean, current_list.clone(), &id, &list_u_p).await { + match specific_update( + config, + clean, + current_list.clone(), + &id, + &list_u_p, + ) + .await + { Ok(ver) => { current_versions.push((disable_version, id)); ver @@ -79,7 +96,10 @@ pub async fn update( list_u_p.inc(1); } - list_u_p.finish_with_message(format!("Updated mods in {}", current_list.id)); + list_u_p.finish_with_message(format!( + "Updated mods in {}", + current_list.id + )); if clean { list_p.set_message("Cleaning"); @@ -100,7 +120,9 @@ pub async fn update( if !clean { let d_p = mp.insert_before( &list_p, - ProgressBar::new(current_versions.len().try_into().unwrap()), + ProgressBar::new( + current_versions.len().try_into().unwrap(), + ), ); d_p.set_style( ProgressStyle::with_template(STYLE_BAR_POS) @@ -115,7 +137,12 @@ pub async fn update( } 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, + current_list.clone(), + ver.0, + ver.1, + )?; }; } @@ -144,7 +171,8 @@ async fn specific_update( id: &str, progress: &ProgressBar, ) -> MLE { - let applicable_versions = versions(&config.apis.modrinth, String::from(id), list.clone()).await; + let applicable_versions = + versions(&config.apis.modrinth, String::from(id), list.clone()).await; let mut versions: Vec = vec![]; @@ -159,7 +187,11 @@ async fn specific_update( let mut current: Vec = vec![]; if clean || (versions.join("|") - != userlist_get_applicable_versions(config, String::from(&list.id), String::from(id))?) + != userlist_get_applicable_versions( + config, + String::from(&list.id), + String::from(id), + )?) { let current_str = extract_current_version(applicable_versions.clone())?; -- cgit v1.2.3