summaryrefslogtreecommitdiff
path: root/src/commands/modification.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2022-12-04 20:32:51 +0100
committerfxqnlr <[email protected]>2022-12-04 20:32:51 +0100
commit2ec20c50e7c02d82b248835988df040bd266b659 (patch)
treea8306a2c07438068dcd190762d3f77e68064b448 /src/commands/modification.rs
parentf3f746be6c1c19c93d440bbc210dec631e2b42bb (diff)
downloadmodlist-2ec20c50e7c02d82b248835988df040bd266b659.tar
modlist-2ec20c50e7c02d82b248835988df040bd266b659.tar.gz
modlist-2ec20c50e7c02d82b248835988df040bd266b659.zip
fully added mod remove; fixed update from NONE
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r--src/commands/modification.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/commands/modification.rs b/src/commands/modification.rs
index ac23970..f36c8c6 100644
--- a/src/commands/modification.rs
+++ b/src/commands/modification.rs
@@ -1,6 +1,6 @@
1use std::io::{Error, ErrorKind}; 1use std::io::{Error, ErrorKind};
2 2
3use crate::{modrinth::{project, versions, extract_current_version, Version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids}, input::{Input, Subcmd}, get_current_list, download_versions}; 3use crate::{modrinth::{project, versions, extract_current_version, Version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, Subcmd}, get_current_list, download_versions, files::delete_version};
4 4
5pub async fn modification(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { 5pub async fn modification(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> {
6 6
@@ -87,6 +87,21 @@ fn remove(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Erro
87 let current_list = get_current_list(config.clone())?; 87 let current_list = get_current_list(config.clone())?;
88 let mod_id = mods_get_id(config.clone(), String::from(&args[0]))?; 88 let mod_id = mods_get_id(config.clone(), String::from(&args[0]))?;
89 89
90 let version = userlist_get_current_version(config.clone(), String::from(&current_list.id), String::from(&mod_id))?;
91
90 //TODO implement remove from modlist if not in any other lists && config clean is true 92 //TODO implement remove from modlist if not in any other lists && config clean is true
91 userlist_remove(config, current_list.id, mod_id) 93 userlist_remove(config.clone(), String::from(&current_list.id), String::from(&mod_id))?;
94 delete_version(current_list, version)?;
95
96 let list_ids = lists_get_all_ids(config.clone())?;
97
98 let mut mod_used = false;
99 for id in list_ids {
100 let mods = userlist_get_all_ids(config.clone(), id)?;
101 if mods.contains(&mod_id) { mod_used = true; break; };
102 };
103
104 if !mod_used { mods_remove(config, mod_id)?; };
105
106 Ok(())
92} 107}