summaryrefslogtreecommitdiff
path: root/src/commands/modification.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-04 12:03:13 +0200
committerfxqnlr <[email protected]>2024-09-04 12:03:13 +0200
commit29635b9e3833296b2c908914104ba7165d22d3d5 (patch)
treef89e2807e664327fa26191d6f017512a87ba38e7 /src/commands/modification.rs
parent6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 (diff)
downloadmodlist-29635b9e3833296b2c908914104ba7165d22d3d5.tar
modlist-29635b9e3833296b2c908914104ba7165d22d3d5.tar.gz
modlist-29635b9e3833296b2c908914104ba7165d22d3d5.zip
remove `# Panics` and fix clippy
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r--src/commands/modification.rs54
1 files changed, 36 insertions, 18 deletions
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
48pub async fn mod_add( 47pub 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
329pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { 346pub 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