diff options
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r-- | src/commands/modification.rs | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 730583d..31931f8 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -11,11 +11,9 @@ use crate::{ | |||
11 | error::{ErrorType, MLError, MLE}, | 11 | error::{ErrorType, MLError, MLE}, |
12 | files::{delete_version, download_versions}, | 12 | files::{delete_version, download_versions}, |
13 | modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, | 13 | modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, |
14 | List, | 14 | List, PROGRESS_CHARS, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | const PROGRESS_CHARS: &str = "#>-"; | ||
18 | |||
19 | #[derive(Debug, Clone)] | 17 | #[derive(Debug, Clone)] |
20 | pub struct AddMod { | 18 | pub struct AddMod { |
21 | pub id: IDSelector, | 19 | pub id: IDSelector, |
@@ -40,7 +38,7 @@ pub struct ProjectInfo { | |||
40 | } | 38 | } |
41 | 39 | ||
42 | pub async fn mod_add( | 40 | pub async fn mod_add( |
43 | config: Cfg, | 41 | config: &Cfg, |
44 | mods: Vec<AddMod>, | 42 | mods: Vec<AddMod>, |
45 | list: List, | 43 | list: List, |
46 | direct_download: bool, | 44 | direct_download: bool, |
@@ -74,11 +72,11 @@ pub async fn mod_add( | |||
74 | info_p.set_style(bar_style.clone()); | 72 | info_p.set_style(bar_style.clone()); |
75 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); | 73 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); |
76 | if !mod_ids.is_empty() { | 74 | if !mod_ids.is_empty() { |
77 | projectinfo.append(&mut get_mod_infos(config.clone(), mod_ids, list.clone()).await?); | 75 | projectinfo.append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); |
78 | info_p.inc(1); | 76 | info_p.inc(1); |
79 | }; | 77 | }; |
80 | if !ver_ids.is_empty() { | 78 | if !ver_ids.is_empty() { |
81 | projectinfo.append(&mut get_ver_info(config.clone(), ver_ids).await?); | 79 | projectinfo.append(&mut get_ver_info(config, ver_ids).await?); |
82 | info_p.inc(1); | 80 | info_p.inc(1); |
83 | }; | 81 | }; |
84 | 82 | ||
@@ -105,7 +103,7 @@ pub async fn mod_add( | |||
105 | }; | 103 | }; |
106 | 104 | ||
107 | match userlist_insert( | 105 | match userlist_insert( |
108 | config.clone(), | 106 | config, |
109 | &list.id, | 107 | &list.id, |
110 | &project.mod_id, | 108 | &project.mod_id, |
111 | ¤t_version_id, | 109 | ¤t_version_id, |
@@ -128,7 +126,7 @@ pub async fn mod_add( | |||
128 | }?; | 126 | }?; |
129 | 127 | ||
130 | match mods_insert( | 128 | match mods_insert( |
131 | config.clone(), | 129 | config, |
132 | &project.mod_id, | 130 | &project.mod_id, |
133 | &project.slug, | 131 | &project.slug, |
134 | &project.title, | 132 | &project.title, |
@@ -161,7 +159,7 @@ pub async fn mod_add( | |||
161 | Ok(()) | 159 | Ok(()) |
162 | } | 160 | } |
163 | 161 | ||
164 | async fn get_mod_infos(config: Cfg, mod_ids: Vec<(String, bool)>, list: List) -> MLE<Vec<ProjectInfo>> { | 162 | async fn get_mod_infos(config: &Cfg, mod_ids: Vec<(String, bool)>, list: List) -> MLE<Vec<ProjectInfo>> { |
165 | 163 | ||
166 | let mut setmap: HashMap<String, bool> = HashMap::new(); | 164 | let mut setmap: HashMap<String, bool> = HashMap::new(); |
167 | 165 | ||
@@ -255,7 +253,7 @@ async fn get_mod_infos(config: Cfg, mod_ids: Vec<(String, bool)>, list: List) -> | |||
255 | Ok(projectinfo) | 253 | Ok(projectinfo) |
256 | } | 254 | } |
257 | 255 | ||
258 | async fn get_ver_info(config: Cfg, ver_ids: Vec<(String, bool)>) -> MLE<Vec<ProjectInfo>> { | 256 | async fn get_ver_info(config: &Cfg, ver_ids: Vec<(String, bool)>) -> MLE<Vec<ProjectInfo>> { |
259 | 257 | ||
260 | let mut setmap: HashMap<String, bool> = HashMap::new(); | 258 | let mut setmap: HashMap<String, bool> = HashMap::new(); |
261 | 259 | ||
@@ -306,16 +304,16 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec<(String, bool)>) -> MLE<Vec<Proj | |||
306 | /// * `config` - config struct | 304 | /// * `config` - config struct |
307 | /// * `id` - name, slug or id of the mod | 305 | /// * `id` - name, slug or id of the mod |
308 | /// * `list` - List struct | 306 | /// * `list` - List struct |
309 | pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { | 307 | pub fn mod_remove(config: &Cfg, id: &str, list: List) -> MLE<()> { |
310 | let mod_id = mods_get_id(&config.data, id)?; | 308 | let mod_id = mods_get_id(&config.data, id)?; |
311 | 309 | ||
312 | println!("Remove mod {} from {}", mods_get_info(&config, &mod_id)?.title, list.id); | 310 | println!("Remove mod {} from {}", mods_get_info(config, &mod_id)?.title, list.id); |
313 | let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?; | 311 | let version = userlist_get_current_version(config, &list.id, &mod_id)?; |
314 | 312 | ||
315 | print!(" └Remove from list"); | 313 | print!(" └Remove from list"); |
316 | //Force flush of stdout, else print! doesn't print instantly | 314 | //Force flush of stdout, else print! doesn't print instantly |
317 | std::io::stdout().flush()?; | 315 | std::io::stdout().flush()?; |
318 | userlist_remove(config.clone(), &list.id, &mod_id)?; | 316 | userlist_remove(config, &list.id, &mod_id)?; |
319 | println!(" ✓"); | 317 | println!(" ✓"); |
320 | 318 | ||
321 | print!(" └Delete file"); | 319 | print!(" └Delete file"); |
@@ -334,12 +332,12 @@ pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { | |||
334 | print!(" └Clean main db table"); | 332 | print!(" └Clean main db table"); |
335 | //Force flush of stdout, else print! doesn't print instantly | 333 | //Force flush of stdout, else print! doesn't print instantly |
336 | std::io::stdout().flush()?; | 334 | std::io::stdout().flush()?; |
337 | let list_ids = lists_get_all_ids(config.clone())?; | 335 | let list_ids = lists_get_all_ids(config)?; |
338 | 336 | ||
339 | // Remove mod from main list if not used elsewhere | 337 | // Remove mod from main list if not used elsewhere |
340 | let mut mod_used = false; | 338 | let mut mod_used = false; |
341 | for id in list_ids { | 339 | for id in list_ids { |
342 | let mods = match userlist_get_all_ids(config.clone(), &id) { | 340 | let mods = match userlist_get_all_ids(config, &id) { |
343 | Ok(m) => m, | 341 | Ok(m) => m, |
344 | Err(err) => { | 342 | Err(err) => { |
345 | if err.to_string() == "Database: NO_MODS_USERLIST" { | 343 | if err.to_string() == "Database: NO_MODS_USERLIST" { |