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 | |
parent | 942558c75200aaad0b4d8561a1f6999f88f843a4 (diff) | |
download | modlist-main.tar modlist-main.tar.gz modlist-main.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/list.rs | 179 | ||||
-rw-r--r-- | src/main.rs | 17 |
2 files changed, 100 insertions, 96 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 | } |
diff --git a/src/main.rs b/src/main.rs index f388a82..a1f0c31 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -4,8 +4,7 @@ use modlist::{ | |||
4 | db::{config_get_current_list, lists_get, lists_get_all_ids}, | 4 | db::{config_get_current_list, lists_get, lists_get_all_ids}, |
5 | download, | 5 | download, |
6 | error::MLE, | 6 | error::MLE, |
7 | export, get_current_list, import, list_add, list_change, list_lists, | 7 | export, import, mod_add, mod_remove, update, AddMod, IDSelector, |
8 | list_remove, list_version, mod_add, mod_remove, update, AddMod, IDSelector, | ||
9 | List, Modloader, VersionLevel, | 8 | List, Modloader, VersionLevel, |
10 | }; | 9 | }; |
11 | 10 | ||
@@ -184,7 +183,7 @@ async fn main() { | |||
184 | } else { | 183 | } else { |
185 | let current = match list { | 184 | let current = match list { |
186 | Some(l) => lists_get(&config, &l).unwrap(), | 185 | Some(l) => lists_get(&config, &l).unwrap(), |
187 | None => get_current_list(&config).unwrap(), | 186 | None => List::get_current_list(&config).unwrap(), |
188 | }; | 187 | }; |
189 | liststack.push(current); | 188 | liststack.push(current); |
190 | } | 189 | } |
@@ -206,7 +205,7 @@ async fn main() { | |||
206 | } else { | 205 | } else { |
207 | let current = match list { | 206 | let current = match list { |
208 | Some(l) => lists_get(&config, &l).unwrap(), | 207 | Some(l) => lists_get(&config, &l).unwrap(), |
209 | None => get_current_list(&config).unwrap(), | 208 | None => List::get_current_list(&config).unwrap(), |
210 | }; | 209 | }; |
211 | liststack.push(current); | 210 | liststack.push(current); |
212 | } | 211 | } |
@@ -309,16 +308,16 @@ async fn handle_list( | |||
309 | .unwrap(), | 308 | .unwrap(), |
310 | }; | 309 | }; |
311 | 310 | ||
312 | list_add(&config, &id, &ver, &ml, &directory) | 311 | List::add(&config, &id, &ver, &ml, &directory) |
313 | } | 312 | } |
314 | ListCommands::Remove { id } => list_remove(&config, &id), | 313 | ListCommands::Remove { id } => List::remove(&config, &id), |
315 | ListCommands::List => list_lists(&config), | 314 | ListCommands::List => List::list(&config), |
316 | ListCommands::Change { id } => list_change(&config, &id), | 315 | ListCommands::Change { id } => List::change(&config, &id), |
317 | ListCommands::Version { | 316 | ListCommands::Version { |
318 | id, | 317 | id, |
319 | version, | 318 | version, |
320 | download, | 319 | download, |
321 | remove, | 320 | remove, |
322 | } => list_version(&config, &id, version, download, remove).await, | 321 | } => List::version(&config, &id, version, download, remove).await, |
323 | } | 322 | } |
324 | } | 323 | } |