From 6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 11:12:04 +0200 Subject: do nearly anything to shut clippy up --- src/commands/list.rs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/commands/list.rs') 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 @@ +#![allow(clippy::module_name_repetitions)] use indicatif::{ProgressBar, ProgressStyle}; use crate::{ @@ -6,7 +7,7 @@ use crate::{ config_change_current_list, config_get_current_list, lists_get, lists_get_all_ids, lists_insert, lists_remove, lists_version, }, - error::{ErrorType, MLError, MLE}, + error::{EType, MLErr, MLE}, update, Modloader, STYLE_OPERATION, }; @@ -18,11 +19,13 @@ pub struct List { pub download_folder: String, } +/// # Errors pub fn get_current_list(config: &Cfg) -> MLE { let id = config_get_current_list(config)?; lists_get(config, &id) } +/// # Errors pub fn list_add( config: &Cfg, id: &str, @@ -31,20 +34,27 @@ pub fn list_add( directory: &str, ) -> MLE<()> { let p = ProgressBar::new_spinner(); - p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_style( + ProgressStyle::with_template(STYLE_OPERATION) + .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, + ); p.set_message(format!("Create {id}")); lists_insert(config, id, mc_version, modloader, directory)?; p.finish_with_message(format!("Created {id}")); Ok(()) } +/// # Errors pub fn list_change(config: &Cfg, id: &str) -> MLE<()> { let p = ProgressBar::new_spinner(); - p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_style( + ProgressStyle::with_template(STYLE_OPERATION) + .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, + ); p.set_message(format!("Change default list to {id}")); if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { - return Err(MLError::new(ErrorType::ArgumentError, "List not found")); + return Err(MLErr::new(EType::ArgumentError, "List not found")); }; config_change_current_list(config, id)?; @@ -52,9 +62,13 @@ pub fn list_change(config: &Cfg, id: &str) -> MLE<()> { Ok(()) } +/// # Errors pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> { let p = ProgressBar::new_spinner(); - p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_style( + ProgressStyle::with_template(STYLE_OPERATION) + .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, + ); p.set_message(format!("Remove {id}")); lists_remove(config, id)?; p.finish_with_message(format!("Removed {id}")); @@ -67,6 +81,7 @@ pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> { /// /// * `config` - The current config /// * `args` - All args, to extract the new version +/// # Errors pub async fn list_version( config: &Cfg, id: &str, @@ -75,7 +90,10 @@ pub async fn list_version( delete: bool, ) -> MLE<()> { let p = ProgressBar::new_spinner(); - p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_style( + ProgressStyle::with_template(STYLE_OPERATION) + .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, + ); p.set_message(format!( "Change version for list {id} to minecraft version: {mc_version}" )); @@ -90,7 +108,8 @@ pub async fn list_version( update(config, vec![list], true, download, delete).await } -pub fn list_list(config: &Cfg) -> MLE<()> { +/// # Errors +pub fn list_lists(config: &Cfg) -> MLE<()> { let lists = lists_get_all_ids(config)?; for list in lists { let l = lists_get(config, &list)?; -- cgit v1.2.3