diff options
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r-- | src/commands/modification.rs | 19 |
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 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | use 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}; | 3 | use 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 | ||
5 | pub async fn modification(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub 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(¤t_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(¤t_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 | } |