diff options
author | fxqnlr <[email protected]> | 2023-05-26 17:40:27 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-05-26 17:40:27 +0200 |
commit | 2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0 (patch) | |
tree | cc8f3522670245775e4be7ac2a1e2ad4fd818c8f /src/commands/list.rs | |
parent | d8554e30029bf43dccce72e982784cd01857b0c4 (diff) | |
download | modlist-2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0.tar modlist-2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0.tar.gz modlist-2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0.zip |
added full progress? cargo fmt
Diffstat (limited to 'src/commands/list.rs')
-rw-r--r-- | src/commands/list.rs | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/src/commands/list.rs b/src/commands/list.rs index 52f14f2..b0a082d 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs | |||
@@ -1,11 +1,13 @@ | |||
1 | use indicatif::{ProgressBar, ProgressStyle}; | ||
2 | |||
1 | use crate::{ | 3 | use crate::{ |
2 | config::Cfg, | 4 | config::Cfg, |
3 | db::{ | 5 | db::{ |
4 | config_change_current_list, config_get_current_list, lists_get, lists_insert, lists_remove, | 6 | config_change_current_list, config_get_current_list, lists_get, lists_get_all_ids, |
5 | lists_version, lists_get_all_ids, | 7 | lists_insert, lists_remove, lists_version, |
6 | }, | 8 | }, |
7 | error::{MLE, MLError, ErrorType}, | 9 | error::{ErrorType, MLError, MLE}, |
8 | update, Modloader, | 10 | update, Modloader, STYLE_OPERATION, |
9 | }; | 11 | }; |
10 | 12 | ||
11 | #[derive(Debug, Clone, PartialEq, Eq)] | 13 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -28,20 +30,35 @@ pub fn list_add( | |||
28 | modloader: &Modloader, | 30 | modloader: &Modloader, |
29 | directory: &str, | 31 | directory: &str, |
30 | ) -> MLE<()> { | 32 | ) -> MLE<()> { |
31 | lists_insert(config, id, mc_version, modloader, directory) | 33 | let p = ProgressBar::new_spinner(); |
34 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); | ||
35 | p.set_message(format!("Create {}", id)); | ||
36 | lists_insert(config, id, mc_version, modloader, directory)?; | ||
37 | p.finish_with_message(format!("Created {}", id)); | ||
38 | Ok(()) | ||
32 | } | 39 | } |
33 | 40 | ||
34 | pub fn list_change(config: &Cfg, id: String) -> MLE<()> { | 41 | pub fn list_change(config: &Cfg, id: &str) -> MLE<()> { |
42 | let p = ProgressBar::new_spinner(); | ||
43 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); | ||
44 | p.set_message(format!("Change default list to {}", id)); | ||
45 | |||
35 | if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { | 46 | if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { |
36 | return Err(MLError::new(ErrorType::ArgumentError, "List not found")); | 47 | return Err(MLError::new(ErrorType::ArgumentError, "List not found")); |
37 | }; | 48 | }; |
38 | println!("Change default list to: {}", id); | 49 | config_change_current_list(config, id)?; |
39 | config_change_current_list(config, id) | 50 | |
51 | p.finish_with_message(format!("Changed default list to {}", id)); | ||
52 | Ok(()) | ||
40 | } | 53 | } |
41 | 54 | ||
42 | pub fn list_remove(config: &Cfg, id: String) -> MLE<()> { | 55 | pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> { |
43 | //TODO add logging | 56 | let p = ProgressBar::new_spinner(); |
44 | lists_remove(config, id) | 57 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); |
58 | p.set_message(format!("Remove {}", id)); | ||
59 | lists_remove(config, id)?; | ||
60 | p.finish_with_message(format!("Removed {}", id)); | ||
61 | Ok(()) | ||
45 | } | 62 | } |
46 | 63 | ||
47 | ///Changing the current lists version and updating it | 64 | ///Changing the current lists version and updating it |
@@ -57,17 +74,20 @@ pub async fn list_version( | |||
57 | download: bool, | 74 | download: bool, |
58 | delete: bool, | 75 | delete: bool, |
59 | ) -> MLE<()> { | 76 | ) -> MLE<()> { |
60 | println!( | 77 | let p = ProgressBar::new_spinner(); |
78 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); | ||
79 | p.set_message(format!( | ||
61 | "Change version for list {} to minecraft version: {}", | 80 | "Change version for list {} to minecraft version: {}", |
62 | id, mc_version | 81 | id, mc_version |
63 | ); | 82 | )); |
64 | 83 | ||
65 | lists_version(config, id, &mc_version)?; | 84 | lists_version(config, id, &mc_version)?; |
66 | 85 | ||
67 | println!( | 86 | p.finish_with_message(format!( |
68 | "\nCheck for updates for new minecraft version in list {}", | 87 | "Changed version for list {} to minecraft version: {}", |
69 | id | 88 | id, mc_version |
70 | ); | 89 | )); |
90 | |||
71 | let list = lists_get(config, id)?; | 91 | let list = lists_get(config, id)?; |
72 | update(config, vec![list], true, download, delete).await | 92 | update(config, vec![list], true, download, delete).await |
73 | } | 93 | } |