diff options
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r-- | src/commands/modification.rs | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 31e50af..454e148 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, ModOptions}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}}; | 1 | use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}}; |
2 | 2 | ||
3 | #[derive(Debug, Clone, PartialEq, Eq)] | 3 | #[derive(Debug, Clone, PartialEq, Eq)] |
4 | pub enum IDSelector { | 4 | pub enum IDSelector { |
@@ -6,24 +6,6 @@ pub enum IDSelector { | |||
6 | VersionID(String) | 6 | VersionID(String) |
7 | } | 7 | } |
8 | 8 | ||
9 | pub async fn modification(config: Cfg, input: Input) -> MLE<()> { | ||
10 | match input.clone().mod_options.ok_or("").unwrap() { | ||
11 | ModOptions::Add => { | ||
12 | add(config, input).await | ||
13 | }, | ||
14 | ModOptions::Remove => { | ||
15 | remove(config, input) | ||
16 | }, | ||
17 | } | ||
18 | } | ||
19 | |||
20 | async fn add(config: Cfg, input: Input) -> MLE<()> { | ||
21 | |||
22 | mods_add(config, vec![input.mod_id.unwrap()], input.list.unwrap(), input.direct_download, input.set_version).await?; | ||
23 | |||
24 | Ok(()) | ||
25 | } | ||
26 | |||
27 | #[derive(Debug, Clone)] | 9 | #[derive(Debug, Clone)] |
28 | pub struct ProjectInfo { | 10 | pub struct ProjectInfo { |
29 | pub mod_id: String, | 11 | pub mod_id: String, |
@@ -34,7 +16,7 @@ pub struct ProjectInfo { | |||
34 | pub download_link: String, | 16 | pub download_link: String, |
35 | } | 17 | } |
36 | 18 | ||
37 | pub async fn mods_add(config: Cfg, ids: Vec<IDSelector>, list: List, direct_download: bool, set_version: bool) -> MLE<()> { | 19 | pub async fn mod_add(config: Cfg, ids: Vec<IDSelector>, list: List, direct_download: bool, set_version: bool) -> MLE<()> { |
38 | println!("Add mods to {}", list.id); | 20 | println!("Add mods to {}", list.id); |
39 | println!(" └Add mods:"); | 21 | println!(" └Add mods:"); |
40 | 22 | ||
@@ -156,22 +138,24 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec<String>) -> MLE<Vec<ProjectInfo> | |||
156 | Ok(projectinfo) | 138 | Ok(projectinfo) |
157 | } | 139 | } |
158 | 140 | ||
159 | fn remove(config: Cfg, input: Input) -> MLE<()> { | 141 | /// Remove mod from a list |
160 | 142 | /// # Arguments | |
161 | let id = match input.clone().mod_id.unwrap() { | 143 | /// |
162 | IDSelector::ModificationID(id) => id, | 144 | /// * `config` - config struct |
163 | IDSelector::VersionID(..) => return Err(MLError::new(ErrorType::ArgumentError, "NO_MOD_ID")), | 145 | /// * `id` - name, slug or id of the mod |
164 | }; | 146 | /// * `list` - List struct |
147 | pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { | ||
165 | 148 | ||
166 | let mod_id = mods_get_id(&config.data, &id)?; | 149 | let mod_id = mods_get_id(&config.data, id)?; |
167 | 150 | ||
168 | let version = userlist_get_current_version(config.clone(), input.clone().list.unwrap().id, String::from(&mod_id))?; | 151 | let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?; |
169 | 152 | ||
170 | userlist_remove(config.clone(), input.clone().list.unwrap().id, String::from(&mod_id))?; | 153 | userlist_remove(config.clone(), &list.id, &mod_id)?; |
171 | delete_version(input.list.unwrap(), version)?; | 154 | delete_version(list, version)?; |
172 | 155 | ||
173 | let list_ids = lists_get_all_ids(config.clone())?; | 156 | let list_ids = lists_get_all_ids(config.clone())?; |
174 | 157 | ||
158 | // Remove mod from main list if not used elsewhere | ||
175 | let mut mod_used = false; | 159 | let mut mod_used = false; |
176 | for id in list_ids { | 160 | for id in list_ids { |
177 | let mods = userlist_get_all_ids(config.clone(), id)?; | 161 | let mods = userlist_get_all_ids(config.clone(), id)?; |