diff options
Diffstat (limited to 'src/commands/list.rs')
-rw-r--r-- | src/commands/list.rs | 85 |
1 files changed, 53 insertions, 32 deletions
diff --git a/src/commands/list.rs b/src/commands/list.rs index 4aa4306..3665446 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, |
5 | lists_version, lists_get_all_ids, | 7 | lists_get_all_ids, 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)] |
@@ -16,31 +18,47 @@ pub struct List { | |||
16 | pub download_folder: String, | 18 | pub download_folder: String, |
17 | } | 19 | } |
18 | 20 | ||
19 | pub fn get_current_list(config: Cfg) -> MLE<List> { | 21 | pub fn get_current_list(config: &Cfg) -> MLE<List> { |
20 | let id = config_get_current_list(config.clone())?; | 22 | let id = config_get_current_list(config)?; |
21 | lists_get(config, id) | 23 | lists_get(config, &id) |
22 | } | 24 | } |
23 | 25 | ||
24 | pub fn list_add( | 26 | pub fn list_add( |
25 | config: Cfg, | 27 | config: &Cfg, |
26 | id: String, | 28 | id: &str, |
27 | mc_version: String, | 29 | mc_version: &str, |
28 | modloader: Modloader, | 30 | modloader: &Modloader, |
29 | directory: String, | 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<()> { |
35 | if lists_get_all_ids(config.clone())?.into_iter().find(|l| l == &id).is_none() { | 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 | |||
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 | lists_remove(config, id) | 56 | let p = ProgressBar::new_spinner(); |
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(()) | ||
44 | } | 62 | } |
45 | 63 | ||
46 | ///Changing the current lists version and updating it | 64 | ///Changing the current lists version and updating it |
@@ -50,31 +68,34 @@ pub fn list_remove(config: Cfg, id: String) -> MLE<()> { | |||
50 | /// * `config` - The current config | 68 | /// * `config` - The current config |
51 | /// * `args` - All args, to extract the new version | 69 | /// * `args` - All args, to extract the new version |
52 | pub async fn list_version( | 70 | pub async fn list_version( |
53 | config: Cfg, | 71 | config: &Cfg, |
54 | id: String, | 72 | id: &str, |
55 | mc_version: String, | 73 | mc_version: String, |
56 | download: bool, | 74 | download: bool, |
57 | delete: bool, | 75 | delete: bool, |
58 | ) -> MLE<()> { | 76 | ) -> MLE<()> { |
59 | println!( | 77 | let p = ProgressBar::new_spinner(); |
78 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); | ||
79 | p.set_message(format!( | ||
60 | "Change version for list {} to minecraft version: {}", | 80 | "Change version for list {} to minecraft version: {}", |
61 | id, mc_version | 81 | id, mc_version |
62 | ); | 82 | )); |
63 | 83 | ||
64 | lists_version(config.clone(), &id, &mc_version)?; | 84 | lists_version(config, id, &mc_version)?; |
85 | |||
86 | p.finish_with_message(format!( | ||
87 | "Changed version for list {} to minecraft version: {}", | ||
88 | id, mc_version | ||
89 | )); | ||
65 | 90 | ||
66 | println!( | 91 | let list = lists_get(config, id)?; |
67 | "\nCheck for updates for new minecraft version in list {}", | ||
68 | id | ||
69 | ); | ||
70 | let list = lists_get(config.clone(), id)?; | ||
71 | update(config, vec![list], true, download, delete).await | 92 | update(config, vec![list], true, download, delete).await |
72 | } | 93 | } |
73 | 94 | ||
74 | pub fn list_list(config: Cfg) -> MLE<()> { | 95 | pub fn list_list(config: &Cfg) -> MLE<()> { |
75 | let lists = lists_get_all_ids(config.clone())?; | 96 | let lists = lists_get_all_ids(config)?; |
76 | for list in lists { | 97 | for list in lists { |
77 | let l = lists_get(config.clone(), list)?; | 98 | let l = lists_get(config, &list)?; |
78 | println!("{}: | {} | {}", l.id, l.mc_version, l.modloader) | 99 | println!("{}: | {} | {}", l.id, l.mc_version, l.modloader) |
79 | } | 100 | } |
80 | Ok(()) | 101 | Ok(()) |