From f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 19 Jan 2023 18:37:42 +0100 Subject: input mostly inplemented, mods missing --- src/commands/update.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/commands/update.rs') diff --git a/src/commands/update.rs b/src/commands/update.rs index ca28130..068c3f3 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -1,5 +1,3 @@ -use std::io::{Error, ErrorKind}; - use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, mods_change_versions}, List, input::Input, files::{delete_version, download_versions, disable_version}, error::{MLE, MLError, ErrorType}}; pub async fn update(config: Cfg, input: Input) -> MLE<()> { @@ -93,7 +91,7 @@ pub async fn cmd_update(config: Cfg, liststack: Vec, clean: bool, direct_d Ok(()) } -async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) -> Result> { +async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) -> MLE { println!("Checking update for '{}' in {}", project.title, list.id); let applicable_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; @@ -114,14 +112,20 @@ async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) //get new versions print!(" | getting new version"); let current_str = extract_current_version(applicable_versions.clone())?; - let current_ver = applicable_versions.into_iter().find(|ver| ver.id == current_str).ok_or("")?; + let current_ver = match applicable_versions.into_iter().find(|ver| ver.id == current_str).ok_or("!no current version in applicable_versions") { + Ok(v) => Ok(v), + Err(e) => Err(MLError::new(ErrorType::Other, e)), + }?; current.push(current_ver.clone()); - let link = current_ver.files.into_iter().find(|f| f.primary).ok_or("")?.url; - userlist_change_versions(config, list.id, current_str, versions.join("|"), link, project.id)?; + let link = match current_ver.files.into_iter().find(|f| f.primary).ok_or("!no primary in links") { + Ok(p) => Ok(p), + Err(e) => Err(MLError::new(ErrorType::Other, e)), + }?.url; + userlist_change_versions(config, list.id, current_str, versions.join("|"), link, project.id); } - if current.is_empty() { return Err(Box::new(Error::new(ErrorKind::NotFound, "NO_UPDATE_AVAILABLE"))) }; + if current.is_empty() { return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE")) }; println!(" | ✔️"); Ok(current[0].clone()) -- cgit v1.2.3