From 638dc58e86ba3bbe31d50e72788c9681d414e0ae Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 12:34:42 +0200 Subject: remove allow module_name_repetition and fix it --- src/commands/list.rs | 179 ++++++++++++++++++++++++++------------------------- src/main.rs | 17 +++-- 2 files changed, 100 insertions(+), 96 deletions(-) (limited to 'src') 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 @@ -#![allow(clippy::module_name_repetitions)] use indicatif::{ProgressBar, ProgressStyle}; use crate::{ @@ -19,101 +18,107 @@ 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) -} +impl List { + /// # 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, - mc_version: &str, - modloader: &Modloader, - directory: &str, -) -> MLE<()> { - let p = ProgressBar::new_spinner(); - 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 add( + config: &Cfg, + id: &str, + mc_version: &str, + modloader: &Modloader, + directory: &str, + ) -> MLE<()> { + let p = ProgressBar::new_spinner(); + 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) - .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, - ); - p.set_message(format!("Change default list to {id}")); + /// # Errors + pub fn change(config: &Cfg, id: &str) -> MLE<()> { + let p = ProgressBar::new_spinner(); + 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(MLErr::new(EType::ArgumentError, "List not found")); - }; - config_change_current_list(config, id)?; + if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { + return Err(MLErr::new(EType::ArgumentError, "List not found")); + }; + config_change_current_list(config, id)?; - p.finish_with_message(format!("Changed default list to {id}")); - Ok(()) -} + p.finish_with_message(format!("Changed default list to {id}")); + Ok(()) + } -/// # Errors -pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> { - let p = ProgressBar::new_spinner(); - 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}")); - Ok(()) -} + /// # Errors + pub fn remove(config: &Cfg, id: &str) -> MLE<()> { + let p = ProgressBar::new_spinner(); + 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}")); + Ok(()) + } -///Changing the current lists version and updating it -/// -/// #Arguments -/// -/// * `config` - The current config -/// * `args` - All args, to extract the new version -/// # Errors -pub async fn list_version( - config: &Cfg, - id: &str, - mc_version: String, - download: bool, - delete: bool, -) -> MLE<()> { - let p = ProgressBar::new_spinner(); - 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}" - )); + ///Changing the current lists version and updating it + /// + /// #Arguments + /// + /// * `config` - The current config + /// * `args` - All args, to extract the new version + /// # Errors + pub async fn version( + config: &Cfg, + id: &str, + mc_version: String, + download: bool, + delete: bool, + ) -> MLE<()> { + let p = ProgressBar::new_spinner(); + 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}" + )); - lists_version(config, id, &mc_version)?; + lists_version(config, id, &mc_version)?; - p.finish_with_message(format!( - "Changed version for list {id} to minecraft version: {mc_version}" - )); + p.finish_with_message(format!( + "Changed version for list {id} to minecraft version: {mc_version}" + )); - let list = lists_get(config, id)?; - update(config, vec![list], true, download, delete).await -} + let list = lists_get(config, id)?; + update(config, vec![list], true, download, delete).await + } -/// # 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)?; - println!("{}: | {} | {}", l.id, l.mc_version, l.modloader); + /// # Errors + pub fn list(config: &Cfg) -> MLE<()> { + let lists = lists_get_all_ids(config)?; + for list in lists { + let l = lists_get(config, &list)?; + println!("{}: | {} | {}", l.id, l.mc_version, l.modloader); + } + Ok(()) } - Ok(()) } 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::{ db::{config_get_current_list, lists_get, lists_get_all_ids}, download, error::MLE, - export, get_current_list, import, list_add, list_change, list_lists, - list_remove, list_version, mod_add, mod_remove, update, AddMod, IDSelector, + export, import, mod_add, mod_remove, update, AddMod, IDSelector, List, Modloader, VersionLevel, }; @@ -184,7 +183,7 @@ async fn main() { } else { let current = match list { Some(l) => lists_get(&config, &l).unwrap(), - None => get_current_list(&config).unwrap(), + None => List::get_current_list(&config).unwrap(), }; liststack.push(current); } @@ -206,7 +205,7 @@ async fn main() { } else { let current = match list { Some(l) => lists_get(&config, &l).unwrap(), - None => get_current_list(&config).unwrap(), + None => List::get_current_list(&config).unwrap(), }; liststack.push(current); } @@ -309,16 +308,16 @@ async fn handle_list( .unwrap(), }; - list_add(&config, &id, &ver, &ml, &directory) + List::add(&config, &id, &ver, &ml, &directory) } - ListCommands::Remove { id } => list_remove(&config, &id), - ListCommands::List => list_lists(&config), - ListCommands::Change { id } => list_change(&config, &id), + ListCommands::Remove { id } => List::remove(&config, &id), + ListCommands::List => List::list(&config), + ListCommands::Change { id } => List::change(&config, &id), ListCommands::Version { id, version, download, remove, - } => list_version(&config, &id, version, download, remove).await, + } => List::version(&config, &id, version, download, remove).await, } } -- cgit v1.2.3