summaryrefslogtreecommitdiff
path: root/src/commands/update.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-04-17 20:30:16 +0200
committerfxqnlr <[email protected]>2023-04-17 20:30:16 +0200
commit93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba (patch)
tree043adeff1c117f3f0e4fe7bffc472c299e01d642 /src/commands/update.rs
parent77d2ac94534b12300b5b7eff6e28023d815708eb (diff)
downloadmodlist-93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba.tar
modlist-93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba.tar.gz
modlist-93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba.zip
added clap cli, modified (basically) all user interface functions;
changed some functions to easier string handling
Diffstat (limited to 'src/commands/update.rs')
-rw-r--r--src/commands/update.rs22
1 files changed, 4 insertions, 18 deletions
diff --git a/src/commands/update.rs b/src/commands/update.rs
index 75bee39..e5751c0 100644
--- a/src/commands/update.rs
+++ b/src/commands/update.rs
@@ -1,21 +1,6 @@
1use crate::{config::Cfg, modrinth::{versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, userlist_get_set_version, mods_get_info}, List, input::Input, files::{delete_version, download_versions, disable_version, clean_list_dir}, error::{MLE, MLError, ErrorType}}; 1use crate::{config::Cfg, modrinth::{versions, extract_current_version, Version}, db::{userlist_get_all_ids, userlist_get_applicable_versions, userlist_change_versions, userlist_get_current_version, userlist_get_set_version, mods_get_info}, List, files::{delete_version, download_versions, disable_version, clean_list_dir}, error::{MLE, MLError, ErrorType}};
2
3pub async fn update(config: Cfg, input: Input) -> MLE<()> {
4 let mut liststack: Vec<List> = vec![];
5 if input.all_lists {
6 let list_ids = lists_get_all_ids(config.clone())?;
7 for id in list_ids {
8 liststack.push(lists_get(config.clone(), id)?);
9 }
10 } else {
11 let current = get_current_list(config.clone())?;
12 println!("Update list {}:", current.id);
13 liststack.push(current)
14 }
15 cmd_update(config, liststack, input.clean, input.direct_download, input.delete_old).await
16}
17 2
18pub async fn cmd_update(config: Cfg, liststack: Vec<List>, clean: bool, direct_download: bool, delete_old: bool) -> MLE<()> { 3pub async fn update(config: Cfg, liststack: Vec<List>, clean: bool, direct_download: bool, delete_old: bool) -> MLE<()> {
19 for current_list in liststack { 4 for current_list in liststack {
20 let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; 5 let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?;
21 6
@@ -34,7 +19,7 @@ pub async fn cmd_update(config: Cfg, liststack: Vec<List>, clean: bool, direct_d
34 } 19 }
35 20
36 //Getting current installed version for disable or delete 21 //Getting current installed version for disable or delete
37 let disable_version = userlist_get_current_version(config.clone(), String::from(&current_list.id), String::from(&id))?; 22 let disable_version = userlist_get_current_version(config.clone(), &current_list.id, &id)?;
38 23
39 updatestack.push( 24 updatestack.push(
40 match specific_update(config.clone(), clean, current_list.clone(), String::from(&id)).await { 25 match specific_update(config.clone(), clean, current_list.clone(), String::from(&id)).await {
@@ -110,6 +95,7 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String) -> ML
110 }?; 95 }?;
111 current.push(current_ver.clone()); 96 current.push(current_ver.clone());
112 97
98 //TODO implement version selection if no primary
113 let link = match current_ver.files.into_iter().find(|f| f.primary).ok_or("!no primary in links") { 99 let link = match current_ver.files.into_iter().find(|f| f.primary).ok_or("!no primary in links") {
114 Ok(p) => Ok(p), 100 Ok(p) => Ok(p),
115 Err(e) => Err(MLError::new(ErrorType::Other, e)), 101 Err(e) => Err(MLError::new(ErrorType::Other, e)),