From 96cc5257de09682df345e768dc2a91303f9b36c9 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 3 Nov 2022 21:34:04 +0100 Subject: added update beginnings; init of tests --- src/commands/add.rs | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 src/commands/add.rs (limited to 'src/commands/add.rs') diff --git a/src/commands/add.rs b/src/commands/add.rs deleted file mode 100644 index ed4a6d8..0000000 --- a/src/commands/add.rs +++ /dev/null @@ -1,52 +0,0 @@ -use std::io::{Error, ErrorKind}; - -use crate::{modrinth::{project, versions}, config::Cfg, db::insert_mod, Modloader, input::Input}; - -pub async fn modification(config: Cfg, args: Option>) -> Result<(), Box> { - - if args.is_none() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))) } - - let arguments = Input::from(args.unwrap().join(" "))?; - - if arguments.args.is_none() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; - - match arguments.command.as_str() { - "add" => { - add(config, arguments.args.unwrap()).await - }, - _ => Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_SUBCOMMAND"))) - } -} - -pub async fn add(config: Cfg, args: Vec) -> Result<(), Box> { - - if args.len() < 1 { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; - - let project = project(String::from(&config.apis.modrinth), &args[0]).await; - - dbg!(&project); - - let loader = Modloader::Fabric; - - if project.versions.is_empty() { panic!("This should never happen"); }; - - let current_version = get_current(config, String::from(&project.id)).await?; - - //add to current list and mod table - match insert_mod(project.id, project.title, current_version, project.versions, loader, String::from("1.19.2")) { - Err(err) => { Err(Box::new(err)) }, - Ok(()) => Ok(()), - } - -} - -async fn get_current(config: Cfg, id: String) -> Result> { - let available_versions = versions(config.apis.modrinth, id, Modloader::Fabric, String::from("1.19.2")).await; - - match available_versions.len() { - 0 => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_VERSIONS_AVAILABLE"))), - //TODO compare publish dates - 1.. => Ok(available_versions[0].id.to_string()), - _ => panic!("available_versions should never be negative"), - } -} -- cgit v1.2.3