summaryrefslogtreecommitdiff
path: root/src/commands/list.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-04 11:12:04 +0200
committerfxqnlr <[email protected]>2024-09-04 11:12:04 +0200
commit6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 (patch)
treeae04cf34582f57699d12ac7b5b486ab065bf8d19 /src/commands/list.rs
parentf5e070cdf6628a5ebd981d373929802317104e24 (diff)
downloadmodlist-6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043.tar
modlist-6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043.tar.gz
modlist-6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043.zip
do nearly anything to shut clippy up
Diffstat (limited to 'src/commands/list.rs')
-rw-r--r--src/commands/list.rs33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/commands/list.rs b/src/commands/list.rs
index 63105cf..47c1dc6 100644
--- a/src/commands/list.rs
+++ b/src/commands/list.rs
@@ -1,3 +1,4 @@
1#![allow(clippy::module_name_repetitions)]
1use indicatif::{ProgressBar, ProgressStyle}; 2use indicatif::{ProgressBar, ProgressStyle};
2 3
3use crate::{ 4use crate::{
@@ -6,7 +7,7 @@ use crate::{
6 config_change_current_list, config_get_current_list, lists_get, 7 config_change_current_list, config_get_current_list, lists_get,
7 lists_get_all_ids, lists_insert, lists_remove, lists_version, 8 lists_get_all_ids, lists_insert, lists_remove, lists_version,
8 }, 9 },
9 error::{ErrorType, MLError, MLE}, 10 error::{EType, MLErr, MLE},
10 update, Modloader, STYLE_OPERATION, 11 update, Modloader, STYLE_OPERATION,
11}; 12};
12 13
@@ -18,11 +19,13 @@ pub struct List {
18 pub download_folder: String, 19 pub download_folder: String,
19} 20}
20 21
22/// # Errors
21pub fn get_current_list(config: &Cfg) -> MLE<List> { 23pub fn get_current_list(config: &Cfg) -> MLE<List> {
22 let id = config_get_current_list(config)?; 24 let id = config_get_current_list(config)?;
23 lists_get(config, &id) 25 lists_get(config, &id)
24} 26}
25 27
28/// # Errors
26pub fn list_add( 29pub fn list_add(
27 config: &Cfg, 30 config: &Cfg,
28 id: &str, 31 id: &str,
@@ -31,20 +34,27 @@ pub fn list_add(
31 directory: &str, 34 directory: &str,
32) -> MLE<()> { 35) -> MLE<()> {
33 let p = ProgressBar::new_spinner(); 36 let p = ProgressBar::new_spinner();
34 p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); 37 p.set_style(
38 ProgressStyle::with_template(STYLE_OPERATION)
39 .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?,
40 );
35 p.set_message(format!("Create {id}")); 41 p.set_message(format!("Create {id}"));
36 lists_insert(config, id, mc_version, modloader, directory)?; 42 lists_insert(config, id, mc_version, modloader, directory)?;
37 p.finish_with_message(format!("Created {id}")); 43 p.finish_with_message(format!("Created {id}"));
38 Ok(()) 44 Ok(())
39} 45}
40 46
47/// # Errors
41pub fn list_change(config: &Cfg, id: &str) -> MLE<()> { 48pub fn list_change(config: &Cfg, id: &str) -> MLE<()> {
42 let p = ProgressBar::new_spinner(); 49 let p = ProgressBar::new_spinner();
43 p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); 50 p.set_style(
51 ProgressStyle::with_template(STYLE_OPERATION)
52 .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?,
53 );
44 p.set_message(format!("Change default list to {id}")); 54 p.set_message(format!("Change default list to {id}"));
45 55
46 if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { 56 if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) {
47 return Err(MLError::new(ErrorType::ArgumentError, "List not found")); 57 return Err(MLErr::new(EType::ArgumentError, "List not found"));
48 }; 58 };
49 config_change_current_list(config, id)?; 59 config_change_current_list(config, id)?;
50 60
@@ -52,9 +62,13 @@ pub fn list_change(config: &Cfg, id: &str) -> MLE<()> {
52 Ok(()) 62 Ok(())
53} 63}
54 64
65/// # Errors
55pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> { 66pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> {
56 let p = ProgressBar::new_spinner(); 67 let p = ProgressBar::new_spinner();
57 p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); 68 p.set_style(
69 ProgressStyle::with_template(STYLE_OPERATION)
70 .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?,
71 );
58 p.set_message(format!("Remove {id}")); 72 p.set_message(format!("Remove {id}"));
59 lists_remove(config, id)?; 73 lists_remove(config, id)?;
60 p.finish_with_message(format!("Removed {id}")); 74 p.finish_with_message(format!("Removed {id}"));
@@ -67,6 +81,7 @@ pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> {
67/// 81///
68/// * `config` - The current config 82/// * `config` - The current config
69/// * `args` - All args, to extract the new version 83/// * `args` - All args, to extract the new version
84/// # Errors
70pub async fn list_version( 85pub async fn list_version(
71 config: &Cfg, 86 config: &Cfg,
72 id: &str, 87 id: &str,
@@ -75,7 +90,10 @@ pub async fn list_version(
75 delete: bool, 90 delete: bool,
76) -> MLE<()> { 91) -> MLE<()> {
77 let p = ProgressBar::new_spinner(); 92 let p = ProgressBar::new_spinner();
78 p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); 93 p.set_style(
94 ProgressStyle::with_template(STYLE_OPERATION)
95 .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?,
96 );
79 p.set_message(format!( 97 p.set_message(format!(
80 "Change version for list {id} to minecraft version: {mc_version}" 98 "Change version for list {id} to minecraft version: {mc_version}"
81 )); 99 ));
@@ -90,7 +108,8 @@ pub async fn list_version(
90 update(config, vec![list], true, download, delete).await 108 update(config, vec![list], true, download, delete).await
91} 109}
92 110
93pub fn list_list(config: &Cfg) -> MLE<()> { 111/// # Errors
112pub fn list_lists(config: &Cfg) -> MLE<()> {
94 let lists = lists_get_all_ids(config)?; 113 let lists = lists_get_all_ids(config)?;
95 for list in lists { 114 for list in lists {
96 let l = lists_get(config, &list)?; 115 let l = lists_get(config, &list)?;