diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/download.rs | 48 | ||||
-rw-r--r-- | src/commands/io.rs | 3 | ||||
-rw-r--r-- | src/commands/modification.rs | 54 | ||||
-rw-r--r-- | src/commands/update.rs | 22 |
4 files changed, 75 insertions, 52 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs index 7321832..7af1066 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -15,7 +15,6 @@ use crate::{ | |||
15 | use crate::{PROGRESS_CHARS, STYLE_BAR_POS}; | 15 | use crate::{PROGRESS_CHARS, STYLE_BAR_POS}; |
16 | 16 | ||
17 | /// # Errors | 17 | /// # Errors |
18 | /// # Panics | ||
19 | pub async fn download( | 18 | pub async fn download( |
20 | config: &Cfg, | 19 | config: &Cfg, |
21 | liststack: Vec<List>, | 20 | liststack: Vec<List>, |
@@ -23,29 +22,31 @@ pub async fn download( | |||
23 | delete_old: bool, | 22 | delete_old: bool, |
24 | ) -> MLE<()> { | 23 | ) -> MLE<()> { |
25 | let mp = MultiProgress::new(); | 24 | let mp = MultiProgress::new(); |
26 | let download_p = | 25 | let download_p = mp.add(ProgressBar::new( |
27 | mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); | 26 | liststack |
27 | .len() | ||
28 | .try_into() | ||
29 | .map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?, | ||
30 | )); | ||
28 | download_p.set_style( | 31 | download_p.set_style( |
29 | ProgressStyle::with_template(STYLE_BAR_POS) | 32 | ProgressStyle::with_template(STYLE_BAR_POS) |
30 | .unwrap() | 33 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
31 | .progress_chars(PROGRESS_CHARS), | 34 | .progress_chars(PROGRESS_CHARS), |
32 | ); | 35 | ); |
33 | 36 | ||
34 | for current_list in liststack { | 37 | for current_list in liststack { |
35 | download_p.set_message(format!("Download in {}", current_list.id)); | 38 | download_p.set_message(format!("Download in {}", current_list.id)); |
36 | 39 | ||
37 | let downloaded_versions = | 40 | let downloaded_versions = get_downloaded_versions(¤t_list)?; |
38 | get_downloaded_versions(¤t_list)?; | ||
39 | let current_version_ids = | 41 | let current_version_ids = |
40 | match userlist_get_all_current_versions_with_mods( | 42 | match userlist_get_all_current_versions_with_mods( |
41 | config, | 43 | config, |
42 | ¤t_list.id, | 44 | ¤t_list.id, |
43 | ) { | 45 | ) { |
44 | Ok(i) => Ok(i), | 46 | Ok(i) => Ok(i), |
45 | Err(e) => Err(MLErr::new( | 47 | Err(e) => { |
46 | EType::DBError, | 48 | Err(MLErr::new(EType::DBError, e.to_string().as_str())) |
47 | e.to_string().as_str(), | 49 | } |
48 | )), | ||
49 | }?; | 50 | }?; |
50 | 51 | ||
51 | let mut to_download: Vec<String> = vec![]; | 52 | let mut to_download: Vec<String> = vec![]; |
@@ -62,8 +63,7 @@ pub async fn download( | |||
62 | to_download.push(current_version); | 63 | to_download.push(current_version); |
63 | } else { | 64 | } else { |
64 | let downloaded_version = current_download | 65 | let downloaded_version = current_download |
65 | .ok_or("SOMETHING_HAS_REALLY_GONE_WRONG") | 66 | .ok_or(MLErr::new(EType::Other, "IDK, WTF"))?; |
66 | .unwrap(); | ||
67 | if ¤t_version != downloaded_version { | 67 | if ¤t_version != downloaded_version { |
68 | to_disable.push(( | 68 | to_disable.push(( |
69 | mod_id.clone(), | 69 | mod_id.clone(), |
@@ -87,7 +87,7 @@ pub async fn download( | |||
87 | download_versions( | 87 | download_versions( |
88 | current_list.clone(), | 88 | current_list.clone(), |
89 | config.clone(), | 89 | config.clone(), |
90 | get_raw_versions(&config.apis.modrinth, to_download).await, | 90 | get_raw_versions(&config.apis.modrinth, to_download).await?, |
91 | &mp, | 91 | &mp, |
92 | &download_p, | 92 | &download_p, |
93 | ) | 93 | ) |
@@ -95,13 +95,18 @@ pub async fn download( | |||
95 | } | 95 | } |
96 | 96 | ||
97 | if !to_disable.is_empty() { | 97 | if !to_disable.is_empty() { |
98 | let d_p = mp.insert_before( | 98 | let d_p = |
99 | &download_p, | 99 | mp.insert_before( |
100 | ProgressBar::new(to_disable.len().try_into().unwrap()), | 100 | &download_p, |
101 | ); | 101 | ProgressBar::new(to_disable.len().try_into().map_err( |
102 | |_| MLErr::new(EType::Other, "ListStackLen"), | ||
103 | )?), | ||
104 | ); | ||
102 | d_p.set_style( | 105 | d_p.set_style( |
103 | ProgressStyle::with_template(STYLE_BAR_POS) | 106 | ProgressStyle::with_template(STYLE_BAR_POS) |
104 | .unwrap() | 107 | .map_err(|_| { |
108 | MLErr::new(EType::LibIndicatif, "template error") | ||
109 | })? | ||
105 | .progress_chars(PROGRESS_CHARS), | 110 | .progress_chars(PROGRESS_CHARS), |
106 | ); | 111 | ); |
107 | for ver in to_disable { | 112 | for ver in to_disable { |
@@ -112,12 +117,7 @@ pub async fn download( | |||
112 | } else { | 117 | } else { |
113 | d_p.set_message(format!("Disable version {}", ver.1)); | 118 | d_p.set_message(format!("Disable version {}", ver.1)); |
114 | d_p.inc(1); | 119 | d_p.inc(1); |
115 | disable_version( | 120 | disable_version(config, ¤t_list, ver.1, ver.0)?; |
116 | config, | ||
117 | ¤t_list, | ||
118 | ver.1, | ||
119 | ver.0, | ||
120 | )?; | ||
121 | }; | 121 | }; |
122 | } | 122 | } |
123 | 123 | ||
diff --git a/src/commands/io.rs b/src/commands/io.rs index c9691c4..3e171f1 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs | |||
@@ -68,7 +68,6 @@ impl ExportList { | |||
68 | } | 68 | } |
69 | 69 | ||
70 | /// # Errors | 70 | /// # Errors |
71 | /// # Panics | ||
72 | pub fn export(config: &Cfg, list: Option<String>) -> MLE<()> { | 71 | pub fn export(config: &Cfg, list: Option<String>) -> MLE<()> { |
73 | let progress = ProgressBar::new_spinner(); | 72 | let progress = ProgressBar::new_spinner(); |
74 | progress.set_style( | 73 | progress.set_style( |
@@ -103,7 +102,7 @@ pub fn export(config: &Cfg, list: Option<String>) -> MLE<()> { | |||
103 | .join("mlexport.toml") | 102 | .join("mlexport.toml") |
104 | .into_os_string() | 103 | .into_os_string() |
105 | .into_string() | 104 | .into_string() |
106 | .unwrap(); | 105 | .map_err(|_| MLErr::new(EType::IoError, "No String"))?; |
107 | 106 | ||
108 | progress.set_message("Create file"); | 107 | progress.set_message("Create file"); |
109 | let mut file = File::create(&filestr)?; | 108 | let mut file = File::create(&filestr)?; |
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 6e6213f..aa1174a 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -44,7 +44,6 @@ pub struct ProjectInfo { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | /// # Errors | 46 | /// # Errors |
47 | /// # Panics | ||
48 | pub async fn mod_add( | 47 | pub async fn mod_add( |
49 | config: &Cfg, | 48 | config: &Cfg, |
50 | mods: Vec<AddMod>, | 49 | mods: Vec<AddMod>, |
@@ -56,11 +55,14 @@ pub async fn mod_add( | |||
56 | let mut mod_ids: Vec<(String, bool)> = Vec::new(); | 55 | let mut mod_ids: Vec<(String, bool)> = Vec::new(); |
57 | let mut ver_ids: Vec<(String, bool)> = Vec::new(); | 56 | let mut ver_ids: Vec<(String, bool)> = Vec::new(); |
58 | 57 | ||
59 | let add_p = mp.add(ProgressBar::new(mods.len().try_into().map_err(|_| MLErr::new(EType::Other, "MODSLENTRY"))?)); | 58 | let add_p = mp.add(ProgressBar::new( |
59 | mods.len() | ||
60 | .try_into() | ||
61 | .map_err(|_| MLErr::new(EType::Other, "MODSLENTRY"))?, | ||
62 | )); | ||
60 | add_p.set_style( | 63 | add_p.set_style( |
61 | ProgressStyle::with_template(STYLE_BAR_POS).map_err(|_| { | 64 | ProgressStyle::with_template(STYLE_BAR_POS) |
62 | MLErr::new(EType::LibIndicatif, "template error") | 65 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
63 | })? | ||
64 | .progress_chars(PROGRESS_CHARS), | 66 | .progress_chars(PROGRESS_CHARS), |
65 | ); | 67 | ); |
66 | add_p.set_message("Sort ids"); | 68 | add_p.set_message("Sort ids"); |
@@ -98,11 +100,16 @@ pub async fn mod_add( | |||
98 | //Adding each mod to the lists and downloadstack | 100 | //Adding each mod to the lists and downloadstack |
99 | let project_p = mp.insert_before( | 101 | let project_p = mp.insert_before( |
100 | &add_p, | 102 | &add_p, |
101 | ProgressBar::new(projectinfo.len().try_into().unwrap()), | 103 | ProgressBar::new( |
104 | projectinfo | ||
105 | .len() | ||
106 | .try_into() | ||
107 | .map_err(|_| MLErr::new(EType::Other, "infolen"))?, | ||
108 | ), | ||
102 | ); | 109 | ); |
103 | project_p.set_style( | 110 | project_p.set_style( |
104 | ProgressStyle::with_template(STYLE_BAR_POS) | 111 | ProgressStyle::with_template(STYLE_BAR_POS) |
105 | .unwrap() | 112 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
106 | .progress_chars(PROGRESS_CHARS), | 113 | .progress_chars(PROGRESS_CHARS), |
107 | ); | 114 | ); |
108 | 115 | ||
@@ -112,7 +119,11 @@ pub async fn mod_add( | |||
112 | let current_version_id = if project.current_version.is_none() { | 119 | let current_version_id = if project.current_version.is_none() { |
113 | String::from("NONE") | 120 | String::from("NONE") |
114 | } else { | 121 | } else { |
115 | project.current_version.clone().unwrap().id | 122 | project |
123 | .current_version | ||
124 | .clone() | ||
125 | .ok_or(MLErr::new(EType::Other, "cur_ver"))? | ||
126 | .id | ||
116 | }; | 127 | }; |
117 | 128 | ||
118 | match userlist_insert( | 129 | match userlist_insert( |
@@ -158,7 +169,11 @@ pub async fn mod_add( | |||
158 | }?; | 169 | }?; |
159 | 170 | ||
160 | if project.current_version.is_some() { | 171 | if project.current_version.is_some() { |
161 | downloadstack.push(project.current_version.unwrap()); | 172 | downloadstack.push( |
173 | project | ||
174 | .current_version | ||
175 | .ok_or(MLErr::new(EType::Other, "cur_ver"))?, | ||
176 | ); | ||
162 | }; | 177 | }; |
163 | 178 | ||
164 | project_p.inc(1); | 179 | project_p.inc(1); |
@@ -202,8 +217,8 @@ async fn get_mod_infos( | |||
202 | 217 | ||
203 | //Get required information from mod_ids | 218 | //Get required information from mod_ids |
204 | let m_projects = match ids.len() { | 219 | let m_projects = match ids.len() { |
205 | 1 => vec![project(&config.apis.modrinth, &ids[0]).await], | 220 | 1 => vec![project(&config.apis.modrinth, &ids[0]).await?], |
206 | 2.. => projects(&config.apis.modrinth, ids).await, | 221 | 2.. => projects(&config.apis.modrinth, ids).await?, |
207 | _ => panic!("PANIC"), | 222 | _ => panic!("PANIC"), |
208 | }; | 223 | }; |
209 | for project in m_projects { | 224 | for project in m_projects { |
@@ -212,7 +227,7 @@ async fn get_mod_infos( | |||
212 | String::from(&project.id), | 227 | String::from(&project.id), |
213 | list.clone(), | 228 | list.clone(), |
214 | ) | 229 | ) |
215 | .await; | 230 | .await?; |
216 | 231 | ||
217 | let mut available_versions_vec: Vec<String> = Vec::new(); | 232 | let mut available_versions_vec: Vec<String> = Vec::new(); |
218 | let current_version: Option<Version>; | 233 | let current_version: Option<Version>; |
@@ -228,7 +243,9 @@ async fn get_mod_infos( | |||
228 | current_version, | 243 | current_version, |
229 | applicable_versions: available_versions_vec, | 244 | applicable_versions: available_versions_vec, |
230 | download_link: file, | 245 | download_link: file, |
231 | set_version: *setmap.get(&project.id).unwrap(), | 246 | set_version: *setmap |
247 | .get(&project.id) | ||
248 | .ok_or(MLErr::new(EType::Other, "not in setmap"))?, | ||
232 | }); | 249 | }); |
233 | } else { | 250 | } else { |
234 | let current_id = | 251 | let current_id = |
@@ -285,12 +302,12 @@ async fn get_ver_info( | |||
285 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); | 302 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); |
286 | 303 | ||
287 | //Get required information from ver_ids | 304 | //Get required information from ver_ids |
288 | let mut v_versions = get_raw_versions(&config.apis.modrinth, ids).await; | 305 | let mut v_versions = get_raw_versions(&config.apis.modrinth, ids).await?; |
289 | let mut v_mod_ids: Vec<String> = Vec::new(); | 306 | let mut v_mod_ids: Vec<String> = Vec::new(); |
290 | for ver in v_versions.clone() { | 307 | for ver in v_versions.clone() { |
291 | v_mod_ids.push(ver.project_id); | 308 | v_mod_ids.push(ver.project_id); |
292 | } | 309 | } |
293 | let mut v_projects = projects(&config.apis.modrinth, v_mod_ids).await; | 310 | let mut v_projects = projects(&config.apis.modrinth, v_mod_ids).await?; |
294 | v_versions.sort_by(|a, b| a.project_id.cmp(&b.project_id)); | 311 | v_versions.sort_by(|a, b| a.project_id.cmp(&b.project_id)); |
295 | v_projects.sort_by(|a, b| a.id.cmp(&b.id)); | 312 | v_projects.sort_by(|a, b| a.id.cmp(&b.id)); |
296 | 313 | ||
@@ -328,9 +345,10 @@ async fn get_ver_info( | |||
328 | /// # Errors | 345 | /// # Errors |
329 | pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { | 346 | pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { |
330 | let progress = ProgressBar::new_spinner(); | 347 | let progress = ProgressBar::new_spinner(); |
331 | progress.set_style(ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { | 348 | progress.set_style( |
332 | MLErr::new(EType::LibIndicatif, "template error") | 349 | ProgressStyle::with_template(STYLE_OPERATION) |
333 | })?); | 350 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, |
351 | ); | ||
334 | 352 | ||
335 | let mod_id = mods_get_id(&config.data, id)?; | 353 | let mod_id = mods_get_id(&config.data, id)?; |
336 | 354 | ||
diff --git a/src/commands/update.rs b/src/commands/update.rs index d0b930d..c7965e3 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -18,7 +18,6 @@ use crate::{ | |||
18 | }; | 18 | }; |
19 | 19 | ||
20 | /// # Errors | 20 | /// # Errors |
21 | /// # Panics | ||
22 | pub async fn update( | 21 | pub async fn update( |
23 | config: &Cfg, | 22 | config: &Cfg, |
24 | liststack: Vec<List>, | 23 | liststack: Vec<List>, |
@@ -44,19 +43,26 @@ pub async fn update( | |||
44 | update_p.set_message(format!("Update {}", current_list.id)); | 43 | update_p.set_message(format!("Update {}", current_list.id)); |
45 | 44 | ||
46 | let list_p = mp.insert_before(&update_p, ProgressBar::new(2)); | 45 | let list_p = mp.insert_before(&update_p, ProgressBar::new(2)); |
47 | list_p | 46 | list_p.set_style( |
48 | .set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); | 47 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { |
48 | MLErr::new(EType::LibIndicatif, "template error") | ||
49 | })?, | ||
50 | ); | ||
49 | list_p.set_message("Update mods"); | 51 | list_p.set_message("Update mods"); |
50 | 52 | ||
51 | let mods = userlist_get_all_ids(config, ¤t_list.id)?; | 53 | let mods = userlist_get_all_ids(config, ¤t_list.id)?; |
52 | 54 | ||
53 | let list_u_p = mp.insert_before( | 55 | let list_u_p = mp.insert_before( |
54 | &list_p, | 56 | &list_p, |
55 | ProgressBar::new(mods.len().try_into().unwrap()), | 57 | ProgressBar::new( |
58 | mods.len() | ||
59 | .try_into() | ||
60 | .map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?, | ||
61 | ), | ||
56 | ); | 62 | ); |
57 | list_u_p.set_style( | 63 | list_u_p.set_style( |
58 | ProgressStyle::with_template(STYLE_BAR_POS) | 64 | ProgressStyle::with_template(STYLE_BAR_POS) |
59 | .unwrap() | 65 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
60 | .progress_chars(PROGRESS_CHARS), | 66 | .progress_chars(PROGRESS_CHARS), |
61 | ); | 67 | ); |
62 | 68 | ||
@@ -129,12 +135,12 @@ pub async fn update( | |||
129 | let d_p = mp.insert_before( | 135 | let d_p = mp.insert_before( |
130 | &list_p, | 136 | &list_p, |
131 | ProgressBar::new( | 137 | ProgressBar::new( |
132 | current_versions.len().try_into().unwrap(), | 138 | current_versions.len().try_into().map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?, |
133 | ), | 139 | ), |
134 | ); | 140 | ); |
135 | d_p.set_style( | 141 | d_p.set_style( |
136 | ProgressStyle::with_template(STYLE_BAR_POS) | 142 | ProgressStyle::with_template(STYLE_BAR_POS) |
137 | .unwrap() | 143 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
138 | .progress_chars(PROGRESS_CHARS), | 144 | .progress_chars(PROGRESS_CHARS), |
139 | ); | 145 | ); |
140 | for ver in current_versions { | 146 | for ver in current_versions { |
@@ -175,7 +181,7 @@ async fn specific_update( | |||
175 | progress: &ProgressBar, | 181 | progress: &ProgressBar, |
176 | ) -> MLE<Version> { | 182 | ) -> MLE<Version> { |
177 | let applicable_versions = | 183 | let applicable_versions = |
178 | versions(&config.apis.modrinth, String::from(id), list.clone()).await; | 184 | versions(&config.apis.modrinth, String::from(id), list.clone()).await?; |
179 | 185 | ||
180 | let mut versions: Vec<String> = vec![]; | 186 | let mut versions: Vec<String> = vec![]; |
181 | 187 | ||