summaryrefslogtreecommitdiff
path: root/src/commands/update.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/update.rs')
-rw-r--r--src/commands/update.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/commands/update.rs b/src/commands/update.rs
index c19c02c..d0b930d 100644
--- a/src/commands/update.rs
+++ b/src/commands/update.rs
@@ -1,3 +1,5 @@
1#![allow(clippy::too_many_lines)]
2
1use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; 3use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
2 4
3use crate::{ 5use crate::{
@@ -7,7 +9,7 @@ use crate::{
7 userlist_get_applicable_versions, userlist_get_current_version, 9 userlist_get_applicable_versions, userlist_get_current_version,
8 userlist_get_set_version, 10 userlist_get_set_version,
9 }, 11 },
10 error::{ErrorType, MLError, MLE}, 12 error::{EType, MLErr, MLE},
11 files::{ 13 files::{
12 clean_list_dir, delete_version, disable_version, download_versions, 14 clean_list_dir, delete_version, disable_version, download_versions,
13 }, 15 },
@@ -15,6 +17,8 @@ use crate::{
15 List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, 17 List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION,
16}; 18};
17 19
20/// # Errors
21/// # Panics
18pub async fn update( 22pub async fn update(
19 config: &Cfg, 23 config: &Cfg,
20 liststack: Vec<List>, 24 liststack: Vec<List>,
@@ -24,11 +28,15 @@ pub async fn update(
24) -> MLE<()> { 28) -> MLE<()> {
25 let mp = MultiProgress::new(); 29 let mp = MultiProgress::new();
26 30
27 let update_p = 31 let update_p = mp.add(ProgressBar::new(
28 mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); 32 liststack
33 .len()
34 .try_into()
35 .map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?,
36 ));
29 update_p.set_style( 37 update_p.set_style(
30 ProgressStyle::with_template(STYLE_BAR_POS) 38 ProgressStyle::with_template(STYLE_BAR_POS)
31 .unwrap() 39 .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?
32 .progress_chars(PROGRESS_CHARS), 40 .progress_chars(PROGRESS_CHARS),
33 ); 41 );
34 42
@@ -133,16 +141,11 @@ pub async fn update(
133 if delete_old { 141 if delete_old {
134 d_p.set_message(format!("Delete version {}", ver.0)); 142 d_p.set_message(format!("Delete version {}", ver.0));
135 d_p.inc(1); 143 d_p.inc(1);
136 delete_version(&current_list, ver.0)?; 144 delete_version(&current_list, &ver.0)?;
137 } else if ver.0 != "NONE" { 145 } else if ver.0 != "NONE" {
138 d_p.set_message(format!("Disable version {}", ver.0)); 146 d_p.set_message(format!("Disable version {}", ver.0));
139 d_p.inc(1); 147 d_p.inc(1);
140 disable_version( 148 disable_version(config, &current_list, ver.0, ver.1)?;
141 config,
142 current_list.clone(),
143 ver.0,
144 ver.1,
145 )?;
146 }; 149 };
147 } 150 }
148 151
@@ -176,12 +179,12 @@ async fn specific_update(
176 179
177 let mut versions: Vec<String> = vec![]; 180 let mut versions: Vec<String> = vec![];
178 181
179 if !applicable_versions.is_empty() { 182 if applicable_versions.is_empty() {
183 versions.push(String::from("NONE"));
184 } else {
180 for ver in &applicable_versions { 185 for ver in &applicable_versions {
181 versions.push(String::from(&ver.id)); 186 versions.push(String::from(&ver.id));
182 } 187 }
183 } else {
184 versions.push(String::from("NONE"));
185 } 188 }
186 189
187 let mut current: Vec<Version> = vec![]; 190 let mut current: Vec<Version> = vec![];
@@ -189,7 +192,7 @@ async fn specific_update(
189 || (versions.join("|") 192 || (versions.join("|")
190 != userlist_get_applicable_versions( 193 != userlist_get_applicable_versions(
191 config, 194 config,
192 String::from(&list.id), 195 &list.id,
193 String::from(id), 196 String::from(id),
194 )?) 197 )?)
195 { 198 {
@@ -209,7 +212,7 @@ async fn specific_update(
209 .ok_or("!no current version in applicable_versions") 212 .ok_or("!no current version in applicable_versions")
210 { 213 {
211 Ok(v) => Ok(v), 214 Ok(v) => Ok(v),
212 Err(e) => Err(MLError::new(ErrorType::Other, e)), 215 Err(e) => Err(MLErr::new(EType::Other, e)),
213 }?; 216 }?;
214 current.push(current_ver.clone()); 217 current.push(current_ver.clone());
215 218
@@ -223,7 +226,7 @@ async fn specific_update(
223 226
224 userlist_change_versions( 227 userlist_change_versions(
225 config, 228 config,
226 list.id, 229 &list.id,
227 current_str, 230 current_str,
228 versions.join("|"), 231 versions.join("|"),
229 link, 232 link,
@@ -232,7 +235,7 @@ async fn specific_update(
232 } 235 }
233 236
234 if current.is_empty() { 237 if current.is_empty() {
235 return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE")); 238 return Err(MLErr::new(EType::ModError, "NO_UPDATE_AVAILABLE"));
236 }; 239 };
237 240
238 Ok(current[0].clone()) 241 Ok(current[0].clone())