From 93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 17 Apr 2023 20:30:16 +0200 Subject: added clap cli, modified (basically) all user interface functions; changed some functions to easier string handling --- src/commands/modification.rs | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) (limited to 'src/commands/modification.rs') diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 31e50af..454e148 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,4 +1,4 @@ -use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, ModOptions}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}}; +use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum IDSelector { @@ -6,24 +6,6 @@ pub enum IDSelector { VersionID(String) } -pub async fn modification(config: Cfg, input: Input) -> MLE<()> { - match input.clone().mod_options.ok_or("").unwrap() { - ModOptions::Add => { - add(config, input).await - }, - ModOptions::Remove => { - remove(config, input) - }, - } -} - -async fn add(config: Cfg, input: Input) -> MLE<()> { - - mods_add(config, vec![input.mod_id.unwrap()], input.list.unwrap(), input.direct_download, input.set_version).await?; - - Ok(()) -} - #[derive(Debug, Clone)] pub struct ProjectInfo { pub mod_id: String, @@ -34,7 +16,7 @@ pub struct ProjectInfo { pub download_link: String, } -pub async fn mods_add(config: Cfg, ids: Vec, list: List, direct_download: bool, set_version: bool) -> MLE<()> { +pub async fn mod_add(config: Cfg, ids: Vec, list: List, direct_download: bool, set_version: bool) -> MLE<()> { println!("Add mods to {}", list.id); println!(" └Add mods:"); @@ -156,22 +138,24 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec) -> MLE Ok(projectinfo) } -fn remove(config: Cfg, input: Input) -> MLE<()> { - - let id = match input.clone().mod_id.unwrap() { - IDSelector::ModificationID(id) => id, - IDSelector::VersionID(..) => return Err(MLError::new(ErrorType::ArgumentError, "NO_MOD_ID")), - }; +/// Remove mod from a list +/// # Arguments +/// +/// * `config` - config struct +/// * `id` - name, slug or id of the mod +/// * `list` - List struct +pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { - let mod_id = mods_get_id(&config.data, &id)?; + let mod_id = mods_get_id(&config.data, id)?; - let version = userlist_get_current_version(config.clone(), input.clone().list.unwrap().id, String::from(&mod_id))?; + let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?; - userlist_remove(config.clone(), input.clone().list.unwrap().id, String::from(&mod_id))?; - delete_version(input.list.unwrap(), version)?; + userlist_remove(config.clone(), &list.id, &mod_id)?; + delete_version(list, version)?; let list_ids = lists_get_all_ids(config.clone())?; + // Remove mod from main list if not used elsewhere let mut mod_used = false; for id in list_ids { let mods = userlist_get_all_ids(config.clone(), id)?; -- cgit v1.2.3