From f87ac1a38af96087e8a6927a6cad7ca19b48d76d Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 19 Dec 2022 16:48:21 +0100 Subject: basic io implementation finished --- src/commands/modification.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/commands/modification.rs') diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 91243fc..f66ce28 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,6 +1,6 @@ use std::io::{Error, ErrorKind}; -use crate::{modrinth::{project, versions, extract_current_version, Version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, Subcmd}, get_current_list, files::{delete_version, download_versions}}; +use crate::{modrinth::{project, versions, extract_current_version, Version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, Subcmd}, get_current_list, files::{delete_version, download_versions}, List}; pub async fn modification(config: Cfg, input: Input) -> Result<(), Box> { @@ -22,10 +22,19 @@ async fn add(config: Cfg, input: Input) -> Result<(), Box if args.is_empty() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; let current_list = get_current_list(config.clone())?; + + mod_add(config, &args[0], current_list, input.disable_download).await?; + + Ok(()) +} - let project = project(String::from(&config.apis.modrinth), &args[0]).await; +pub async fn mod_add(config: Cfg, mod_id: &str, list: List, disable_download: bool) -> Result<(), Box> { + + println!("Adding mod {}", mod_id); + + let project = project(String::from(&config.apis.modrinth), &mod_id).await; - let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), current_list.clone()).await; + let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; let mut available_versions_vec: Vec = Vec::new(); let current_version: Option; @@ -52,15 +61,15 @@ async fn add(config: Cfg, input: Input) -> Result<(), Box } //add to current list and mod table - match userlist_get_all_ids(config.clone(), current_list.clone().id) { + match userlist_get_all_ids(config.clone(), list.clone().id) { Ok(mods) => { if mods.contains(&project.id) { return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } else { - userlist_insert(config.clone(), String::from(¤t_list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?; + userlist_insert(config.clone(), String::from(&list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?; } }, - Err(..) => userlist_insert(config.clone(), String::from(¤t_list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?, + Err(..) => userlist_insert(config.clone(), String::from(&list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?, }; match mods_get_all_ids(config.clone()) { @@ -75,8 +84,8 @@ async fn add(config: Cfg, input: Input) -> Result<(), Box mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; }, }; - - if !input.disable_download && current_version.is_some() { download_versions(current_list, vec![current_version.unwrap()]).await?; } + + if !disable_download && current_version.is_some() { download_versions(list, vec![current_version.unwrap()]).await?; }; Ok(()) } -- cgit v1.2.3