summaryrefslogtreecommitdiff
path: root/src/commands/list.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-05-29 18:02:08 +0200
committerfx <[email protected]>2023-05-29 18:02:08 +0200
commitd3870a2efa74e68c643dfb4aef32edc2536503b0 (patch)
tree116075aaa57c35afca2749719d450c3cb473ab3e /src/commands/list.rs
parent5a2ea0755b29a8811aeeec1c73679c5783082628 (diff)
parentc7ecf3019a75dc0ab1a0aefeb9b880899fc8a231 (diff)
downloadmodlist-d3870a2efa74e68c643dfb4aef32edc2536503b0.tar
modlist-d3870a2efa74e68c643dfb4aef32edc2536503b0.tar.gz
modlist-d3870a2efa74e68c643dfb4aef32edc2536503b0.zip
Merge pull request 'multithreaded' (#6) from multithreaded into master
Reviewed-on: http://raspberrypi.fritz.box:7920/fx/modlist/pulls/6
Diffstat (limited to 'src/commands/list.rs')
-rw-r--r--src/commands/list.rs85
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 @@
1use indicatif::{ProgressBar, ProgressStyle};
2
1use crate::{ 3use 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
19pub fn get_current_list(config: Cfg) -> MLE<List> { 21pub 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
24pub fn list_add( 26pub 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
34pub fn list_change(config: Cfg, id: String) -> MLE<()> { 41pub 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
42pub fn list_remove(config: Cfg, id: String) -> MLE<()> { 55pub 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
52pub async fn list_version( 70pub 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
74pub fn list_list(config: Cfg) -> MLE<()> { 95pub 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(())