From 57ab6addda10a49c18dc09208dfb319c0205e869 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 26 Jan 2023 17:23:06 +0100 Subject: Todos; fixed input with "-" --- src/commands/modification.rs | 4 +++- src/commands/update.rs | 3 ++- src/files.rs | 1 - src/input.rs | 51 +++++++++++++++++++++++++++++--------------- src/main.rs | 4 ++-- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 6a03b35..c194202 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -20,6 +20,7 @@ async fn add(config: Cfg, input: Input) -> MLE<()> { pub async fn mod_add(config: Cfg, mod_id: Vec, list: List, disable_download: bool) -> MLE<()> { + //Fix printing (its horrible) println!("Adding mod(s) {:?}", mod_id); let projects = if mod_id.len() == 1 { vec![project(String::from(&config.apis.modrinth), &mod_id[0]).await] @@ -87,7 +88,8 @@ pub async fn mod_add(config: Cfg, mod_id: Vec, list: List, disable_downl } fn remove(config: Cfg, input: Input) -> MLE<()> { - + + //TODO inplement deletion by slug or title let mod_id = mods_get_id(config.clone(), input.clone().mod_id.unwrap())?; let version = userlist_get_current_version(config.clone(), input.clone().list.unwrap().id, String::from(&mod_id))?; diff --git a/src/commands/update.rs b/src/commands/update.rs index f8bdb82..f71f537 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -139,6 +139,7 @@ async fn download_updates_test() { use crate::{modrinth::{Version, VersionFile, Hash, VersionType}, Modloader, List}; + let config = Cfg::init("modlist.toml").unwrap(); let current_list = List { id: String::from("..."), mc_version: String::from("..."), modloader: Modloader::Forge, download_folder: String::from("./dl") }; let versions = vec![Version { @@ -171,5 +172,5 @@ async fn download_updates_test() { "fabric".to_string() ] }]; - assert!(download_versions(current_list, versions).await.is_ok()) + assert!(download_versions(current_list, config, versions).await.is_ok()) } diff --git a/src/files.rs b/src/files.rs index 0d7dc0a..ecb6e3e 100644 --- a/src/files.rs +++ b/src/files.rs @@ -11,7 +11,6 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec) println!("Download to directory from: {} ({})", list.id, dl_path); for ver in versions { - //TODO get project name instead of projectid from db let project_name = mods_get_name(config.clone(), &ver.project_id)?; print!("\t({})Download version {}", project_name, ver.id); std::io::stdout().flush().unwrap(); diff --git a/src/input.rs b/src/input.rs index a41f671..144f22a 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,4 +1,4 @@ -use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_get, get_current_list, List}; +use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_get, get_current_list, List, modrinth::{get_minecraft_version, MCVersionType}}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct Input { @@ -54,10 +54,8 @@ pub enum IoOptions { impl Input { fn from(config: Cfg, input: Vec) -> MLE { let input_string = input.join(" "); - let mut args: Vec<&str> = input_string.split('-').collect(); - args.reverse(); - args.pop(); - args.reverse(); + let mut args: Vec<&str> = input_string.split(" -").collect(); + args[0] = args[0].split_at(1).1; let mut command: Option = None; @@ -95,6 +93,8 @@ impl Input { mod_options = Some(ModOptions::Add); if arg_split.len() == 2 { mod_id = Some(String::from(arg_split[1])); + } else { + return Err(MLError::new(ErrorType::ArgumentError, "Please specify a list mod slug or id")); } }, "mv" => { @@ -102,6 +102,8 @@ impl Input { mod_options = Some(ModOptions::Add); if arg_split.len() == 2 { mod_version = Some(String::from(arg_split[1])); + } else { + return Err(MLError::new(ErrorType::ArgumentError, "Please specify a version id")); }; }, "mr" => { @@ -109,7 +111,9 @@ impl Input { mod_options = Some(ModOptions::Remove); if arg_split.len() == 2 { mod_id = Some(String::from(arg_split[1])); - } + } else { + return Err(MLError::new(ErrorType::ArgumentError, "Please specify a mod id")); + }; }, "set_version" => { set_version = true; @@ -120,7 +124,7 @@ impl Input { "clean" => { clean = true; }, - "no-download" => { + "no_download" => { direct_download = false; }, "delete_old" => { @@ -136,7 +140,11 @@ impl Input { "la" => { command = Some(Cmd::List); list_options = Some(ListOptions::Add); - list_id = Some(String::from(arg_split[1])); + if arg_split.len() == 2 { + list_id = Some(String::from(arg_split[1])); + } else { + return Err(MLError::new(ErrorType::ArgumentError, "Please give the new list an id")); + } }, "lr" => { command = Some(Cmd::List); @@ -163,10 +171,18 @@ impl Input { } }, "ml" => { - modloader = Some(Modloader::from(arg_split[1])?); + if arg_split.len() == 2 { + modloader = Some(Modloader::from(arg_split[1])?); + } else { + return Err(MLError::new(ErrorType::ArgumentError, "Please specify a modloader")); + } }, "dir" => { - directory = Some(String::from(arg_split[1])); + if arg_split.len() == 2 { + directory = Some(String::from(arg_split[1])); + } else { + return Err(MLError::new(ErrorType::ArgumentError, "Please specify a directory")); + } }, "export" => { command = Some(Cmd::Io); @@ -212,18 +228,16 @@ pub async fn get_input(config: Cfg, args: Vec) -> MLE { match input.clone().command.unwrap() { Cmd::Mod => check_mod(input, config), - Cmd::List => check_list(input, config), + Cmd::List => check_list(input, config).await, _ => Ok(input), } } -//Move checks to commands? translate to variables there? fn check_mod(mut input: Input, config: Cfg) -> MLE { if input.mod_options.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No mod option")); }; match input.clone().mod_options.unwrap() { - //Check for MV if no mod-id on both ModOptions::Add => { if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No mod id/slug or version id")); }; if input.list_id.is_none() { input.list = Some(get_current_list(config.clone())?); }; @@ -236,7 +250,7 @@ fn check_mod(mut input: Input, config: Cfg) -> MLE { } } -fn check_list(mut input: Input, config: Cfg) -> MLE { +async fn check_list(mut input: Input, config: Cfg) -> MLE { if input.list_options.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_ARGUMENT")); }; @@ -245,11 +259,14 @@ fn check_list(mut input: Input, config: Cfg) -> MLE { if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no list id specified")); }; if input.list_mcversion.is_none() { println!("No Minecraft Version specified, defaulting to latest release"); - //TODO Get latest version - input.list_mcversion = Some(String::from("1.19.3")); + input.list_mcversion = Some(get_minecraft_version(config.apis.modrinth, MCVersionType::Release).await); + }; + if input.directory.is_none() { + let id = input.clone().list_id.unwrap(); + println!("No download directory specified, defaulting to ./downloads/{}", id); + input.directory = Some(format!("./downloads/{}", id)) }; if input.modloader.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no modloader specified")); }; - if input.directory.is_none() { input.directory = Some(format!("./downloads/{}", input.clone().list_id.expect("earlier if failed"))) }; Ok(input) }, ListOptions::Remove => { diff --git a/src/main.rs b/src/main.rs index 2fca691..d177c3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use std::{env, process}; -use modlist::{config::Cfg, input::{get_input, Cmd}, update, download, list, io}; +use modlist::{config::Cfg, input::{get_input, Cmd}, update, download, list, io, modification}; #[tokio::main] async fn main() { @@ -23,7 +23,7 @@ async fn main() { match input.clone().command.unwrap() { Cmd::Mod => { - Ok(()) + modification(config, input).await }, Cmd::List => { list(config, input).await -- cgit v1.2.3