summaryrefslogtreecommitdiff
path: root/src/commands/update.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/update.rs')
-rw-r--r--src/commands/update.rs18
1 files changed, 11 insertions, 7 deletions
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 @@
1use std::io::{Error, ErrorKind};
2
3use 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}}; 1use 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}};
4 2
5pub async fn update(config: Cfg, input: Input) -> MLE<()> { 3pub async fn update(config: Cfg, input: Input) -> MLE<()> {
@@ -93,7 +91,7 @@ pub async fn cmd_update(config: Cfg, liststack: Vec<List>, clean: bool, direct_d
93 Ok(()) 91 Ok(())
94} 92}
95 93
96async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) -> Result<Version, Box<dyn std::error::Error>> { 94async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) -> MLE<Version> {
97 println!("Checking update for '{}' in {}", project.title, list.id); 95 println!("Checking update for '{}' in {}", project.title, list.id);
98 96
99 let applicable_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; 97 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)
114 //get new versions 112 //get new versions
115 print!(" | getting new version"); 113 print!(" | getting new version");
116 let current_str = extract_current_version(applicable_versions.clone())?; 114 let current_str = extract_current_version(applicable_versions.clone())?;
117 let current_ver = applicable_versions.into_iter().find(|ver| ver.id == current_str).ok_or("")?; 115 let current_ver = match applicable_versions.into_iter().find(|ver| ver.id == current_str).ok_or("!no current version in applicable_versions") {
116 Ok(v) => Ok(v),
117 Err(e) => Err(MLError::new(ErrorType::Other, e)),
118 }?;
118 current.push(current_ver.clone()); 119 current.push(current_ver.clone());
119 120
120 let link = current_ver.files.into_iter().find(|f| f.primary).ok_or("")?.url; 121 let link = match current_ver.files.into_iter().find(|f| f.primary).ok_or("!no primary in links") {
121 userlist_change_versions(config, list.id, current_str, versions.join("|"), link, project.id)?; 122 Ok(p) => Ok(p),
123 Err(e) => Err(MLError::new(ErrorType::Other, e)),
124 }?.url;
125 userlist_change_versions(config, list.id, current_str, versions.join("|"), link, project.id);
122 } 126 }
123 127
124 if current.is_empty() { return Err(Box::new(Error::new(ErrorKind::NotFound, "NO_UPDATE_AVAILABLE"))) }; 128 if current.is_empty() { return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE")) };
125 129
126 println!(" | ✔️"); 130 println!(" | ✔️");
127 Ok(current[0].clone()) 131 Ok(current[0].clone())