diff options
author | fxqnlr <[email protected]> | 2024-09-04 12:34:42 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-04 12:34:42 +0200 |
commit | 638dc58e86ba3bbe31d50e72788c9681d414e0ae (patch) | |
tree | f8e7941c8a37f808246a392eeb6bf1780ae2b3de /src/commands | |
parent | 942558c75200aaad0b4d8561a1f6999f88f843a4 (diff) | |
download | modlist-638dc58e86ba3bbe31d50e72788c9681d414e0ae.tar modlist-638dc58e86ba3bbe31d50e72788c9681d414e0ae.tar.gz modlist-638dc58e86ba3bbe31d50e72788c9681d414e0ae.zip |
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/list.rs | 179 |
1 files changed, 92 insertions, 87 deletions
diff --git a/src/commands/list.rs b/src/commands/list.rs index 47c1dc6..148bd16 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs | |||
@@ -1,4 +1,3 @@ | |||
1 | #![allow(clippy::module_name_repetitions)] | ||
2 | use indicatif::{ProgressBar, ProgressStyle}; | 1 | use indicatif::{ProgressBar, ProgressStyle}; |
3 | 2 | ||
4 | use crate::{ | 3 | use crate::{ |
@@ -19,101 +18,107 @@ pub struct List { | |||
19 | pub download_folder: String, | 18 | pub download_folder: String, |
20 | } | 19 | } |
21 | 20 | ||
22 | /// # Errors | 21 | impl List { |
23 | pub fn get_current_list(config: &Cfg) -> MLE<List> { | 22 | /// # Errors |
24 | let id = config_get_current_list(config)?; | 23 | pub fn get_current_list(config: &Cfg) -> MLE<List> { |
25 | lists_get(config, &id) | 24 | let id = config_get_current_list(config)?; |
26 | } | 25 | lists_get(config, &id) |
26 | } | ||
27 | 27 | ||
28 | /// # Errors | 28 | /// # Errors |
29 | pub fn list_add( | 29 | pub fn add( |
30 | config: &Cfg, | 30 | config: &Cfg, |
31 | id: &str, | 31 | id: &str, |
32 | mc_version: &str, | 32 | mc_version: &str, |
33 | modloader: &Modloader, | 33 | modloader: &Modloader, |
34 | directory: &str, | 34 | directory: &str, |
35 | ) -> MLE<()> { | 35 | ) -> MLE<()> { |
36 | let p = ProgressBar::new_spinner(); | 36 | let p = ProgressBar::new_spinner(); |
37 | p.set_style( | 37 | p.set_style( |
38 | ProgressStyle::with_template(STYLE_OPERATION) | 38 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { |
39 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, | 39 | MLErr::new(EType::LibIndicatif, "template error") |
40 | ); | 40 | })?, |
41 | p.set_message(format!("Create {id}")); | 41 | ); |
42 | lists_insert(config, id, mc_version, modloader, directory)?; | 42 | p.set_message(format!("Create {id}")); |
43 | p.finish_with_message(format!("Created {id}")); | 43 | lists_insert(config, id, mc_version, modloader, directory)?; |
44 | Ok(()) | 44 | p.finish_with_message(format!("Created {id}")); |
45 | } | 45 | Ok(()) |
46 | } | ||
46 | 47 | ||
47 | /// # Errors | 48 | /// # Errors |
48 | pub fn list_change(config: &Cfg, id: &str) -> MLE<()> { | 49 | pub fn change(config: &Cfg, id: &str) -> MLE<()> { |
49 | let p = ProgressBar::new_spinner(); | 50 | let p = ProgressBar::new_spinner(); |
50 | p.set_style( | 51 | p.set_style( |
51 | ProgressStyle::with_template(STYLE_OPERATION) | 52 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { |
52 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, | 53 | MLErr::new(EType::LibIndicatif, "template error") |
53 | ); | 54 | })?, |
54 | p.set_message(format!("Change default list to {id}")); | 55 | ); |
56 | p.set_message(format!("Change default list to {id}")); | ||
55 | 57 | ||
56 | if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { | 58 | if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { |
57 | return Err(MLErr::new(EType::ArgumentError, "List not found")); | 59 | return Err(MLErr::new(EType::ArgumentError, "List not found")); |
58 | }; | 60 | }; |
59 | config_change_current_list(config, id)?; | 61 | config_change_current_list(config, id)?; |
60 | 62 | ||
61 | p.finish_with_message(format!("Changed default list to {id}")); | 63 | p.finish_with_message(format!("Changed default list to {id}")); |
62 | Ok(()) | 64 | Ok(()) |
63 | } | 65 | } |
64 | 66 | ||
65 | /// # Errors | 67 | /// # Errors |
66 | pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> { | 68 | pub fn remove(config: &Cfg, id: &str) -> MLE<()> { |
67 | let p = ProgressBar::new_spinner(); | 69 | let p = ProgressBar::new_spinner(); |
68 | p.set_style( | 70 | p.set_style( |
69 | ProgressStyle::with_template(STYLE_OPERATION) | 71 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { |
70 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, | 72 | MLErr::new(EType::LibIndicatif, "template error") |
71 | ); | 73 | })?, |
72 | p.set_message(format!("Remove {id}")); | 74 | ); |
73 | lists_remove(config, id)?; | 75 | p.set_message(format!("Remove {id}")); |
74 | p.finish_with_message(format!("Removed {id}")); | 76 | lists_remove(config, id)?; |
75 | Ok(()) | 77 | p.finish_with_message(format!("Removed {id}")); |
76 | } | 78 | Ok(()) |
79 | } | ||
77 | 80 | ||
78 | ///Changing the current lists version and updating it | 81 | ///Changing the current lists version and updating it |
79 | /// | 82 | /// |
80 | /// #Arguments | 83 | /// #Arguments |
81 | /// | 84 | /// |
82 | /// * `config` - The current config | 85 | /// * `config` - The current config |
83 | /// * `args` - All args, to extract the new version | 86 | /// * `args` - All args, to extract the new version |
84 | /// # Errors | 87 | /// # Errors |
85 | pub async fn list_version( | 88 | pub async fn version( |
86 | config: &Cfg, | 89 | config: &Cfg, |
87 | id: &str, | 90 | id: &str, |
88 | mc_version: String, | 91 | mc_version: String, |
89 | download: bool, | 92 | download: bool, |
90 | delete: bool, | 93 | delete: bool, |
91 | ) -> MLE<()> { | 94 | ) -> MLE<()> { |
92 | let p = ProgressBar::new_spinner(); | 95 | let p = ProgressBar::new_spinner(); |
93 | p.set_style( | 96 | p.set_style( |
94 | ProgressStyle::with_template(STYLE_OPERATION) | 97 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { |
95 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, | 98 | MLErr::new(EType::LibIndicatif, "template error") |
96 | ); | 99 | })?, |
97 | p.set_message(format!( | 100 | ); |
98 | "Change version for list {id} to minecraft version: {mc_version}" | 101 | p.set_message(format!( |
99 | )); | 102 | "Change version for list {id} to minecraft version: {mc_version}" |
103 | )); | ||
100 | 104 | ||
101 | lists_version(config, id, &mc_version)?; | 105 | lists_version(config, id, &mc_version)?; |
102 | 106 | ||
103 | p.finish_with_message(format!( | 107 | p.finish_with_message(format!( |
104 | "Changed version for list {id} to minecraft version: {mc_version}" | 108 | "Changed version for list {id} to minecraft version: {mc_version}" |
105 | )); | 109 | )); |
106 | 110 | ||
107 | let list = lists_get(config, id)?; | 111 | let list = lists_get(config, id)?; |
108 | update(config, vec![list], true, download, delete).await | 112 | update(config, vec![list], true, download, delete).await |
109 | } | 113 | } |
110 | 114 | ||
111 | /// # Errors | 115 | /// # Errors |
112 | pub fn list_lists(config: &Cfg) -> MLE<()> { | 116 | pub fn list(config: &Cfg) -> MLE<()> { |
113 | let lists = lists_get_all_ids(config)?; | 117 | let lists = lists_get_all_ids(config)?; |
114 | for list in lists { | 118 | for list in lists { |
115 | let l = lists_get(config, &list)?; | 119 | let l = lists_get(config, &list)?; |
116 | println!("{}: | {} | {}", l.id, l.mc_version, l.modloader); | 120 | println!("{}: | {} | {}", l.id, l.mc_version, l.modloader); |
121 | } | ||
122 | Ok(()) | ||
117 | } | 123 | } |
118 | Ok(()) | ||
119 | } | 124 | } |