From 11e64fc7560de3cd0def718edf68c31e3dc8be72 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 15:08:55 +0200 Subject: move stuff around, remove lib.rs for overview --- src/commands/download.rs | 2 +- src/commands/io.rs | 7 +- src/commands/list.rs | 193 +++++++++++++++++++------------------------ src/commands/mod.rs | 11 --- src/commands/modification.rs | 35 +------- src/commands/update.rs | 11 +-- 6 files changed, 95 insertions(+), 164 deletions(-) delete mode 100644 src/commands/mod.rs (limited to 'src/commands') diff --git a/src/commands/download.rs b/src/commands/download.rs index 7ea5c29..269d5d3 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -1,5 +1,6 @@ use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; +use crate::apis::modrinth::get_raw_versions; use crate::{config::Cfg, List}; use crate::{ db::userlist_get_all_current_versions_with_mods, @@ -8,7 +9,6 @@ use crate::{ clean_list_dir, delete_version, disable_version, download_versions, get_downloaded_versions, }, - modrinth::get_raw_versions, }; use crate::{PROGRESS_CHARS, STYLE_BAR_POS}; diff --git a/src/commands/io.rs b/src/commands/io.rs index 3e171f1..dea0d84 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -4,13 +4,10 @@ use std::fs::File; use std::io::prelude::*; use crate::{ - config::Cfg, - db::{ + config::Cfg, data::modification::{AddMod, IDSelector}, db::{ lists_get, lists_get_all_ids, lists_insert, userlist_get_all_ids, userlist_get_current_version, userlist_get_set_version, - }, - error::{EType, MLErr, MLE}, - mod_add, AddMod, IDSelector, List, Modloader, STYLE_OPERATION, + }, error::{EType, MLErr, MLE}, mod_add, List, Modloader, STYLE_OPERATION }; #[derive(Debug, Serialize, Deserialize)] diff --git a/src/commands/list.rs b/src/commands/list.rs index 148bd16..23a9f0f 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,124 +1,105 @@ use indicatif::{ProgressBar, ProgressStyle}; use crate::{ - config::Cfg, - db::{ - config_change_current_list, config_get_current_list, lists_get, + config::Cfg, data::modloader::Modloader, db::{ + config_change_current_list, lists_get, lists_get_all_ids, lists_insert, lists_remove, lists_version, - }, - error::{EType, MLErr, MLE}, - update, Modloader, STYLE_OPERATION, + }, error::{EType, MLErr, MLE}, update, STYLE_OPERATION }; -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct List { - pub id: String, - pub mc_version: String, - pub modloader: Modloader, - pub download_folder: String, +/// # 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(()) } -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 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 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 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 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(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(()) +/// # 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(()) } diff --git a/src/commands/mod.rs b/src/commands/mod.rs deleted file mode 100644 index 0f13056..0000000 --- a/src/commands/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub mod download; -pub mod io; -pub mod list; -pub mod modification; -pub mod update; - -pub use download::*; -pub use io::*; -pub use list::*; -pub use modification::*; -pub use update::*; diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 8f115ee..d20f575 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -3,44 +3,13 @@ use std::collections::HashMap; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use crate::{ - config::Cfg, - db::{ + apis::modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, config::Cfg, data::{modification::{AddMod, IDSelector}, project::ProjectInfo}, db::{ lists_get_all_ids, mods_get_id, mods_get_info, mods_insert, mods_remove, userlist_get_all_ids, userlist_get_current_version, userlist_insert, userlist_remove, - }, - error::{EType, MLErr, MLE}, - files::{delete_version, download_versions}, - modrinth::{ - extract_current_version, get_raw_versions, project, projects, versions, - Version, - }, - List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, + }, error::{EType, MLErr, MLE}, files::{delete_version, download_versions}, List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION }; -#[derive(Debug)] -pub struct AddMod { - pub id: IDSelector, - pub set_version: bool, -} - -#[derive(Debug, PartialEq, Eq)] -pub enum IDSelector { - ModificationID(String), - VersionID(String), -} - -#[derive(Debug, Clone)] -pub struct ProjectInfo { - pub mod_id: String, - pub slug: String, - pub title: String, - pub current_version: Option, - pub applicable_versions: Vec, - pub download_link: String, - pub set_version: bool, -} - /// # Errors pub async fn mod_add( config: &Cfg, diff --git a/src/commands/update.rs b/src/commands/update.rs index f83030d..721ced5 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -1,18 +1,13 @@ use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use crate::{ - config::Cfg, - db::{ + apis::modrinth::{extract_current_version, versions, Version}, config::Cfg, data::list::List, db::{ mods_get_info, userlist_change_versions, userlist_get_all_ids, userlist_get_applicable_versions, userlist_get_current_version, userlist_get_set_version, - }, - error::{EType, MLErr, MLE}, - files::{ + }, error::{EType, MLErr, MLE}, files::{ clean_list_dir, delete_version, disable_version, download_versions, - }, - modrinth::{extract_current_version, versions, Version}, - List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, + }, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION }; /// # Errors -- cgit v1.2.3