From 9c984cef9a2d0fb223635617934959480e8ca2df Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 19 Feb 2023 11:49:23 +0100 Subject: Added adding of specific mod-version --- src/input.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/input.rs') diff --git a/src/input.rs b/src/input.rs index 17fc773..6c62ab7 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,11 +1,10 @@ -use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_get, get_current_list, List, modrinth::{get_minecraft_version, MCVersionType}}; +use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_get, get_current_list, List, modrinth::{get_minecraft_version, MCVersionType}, IDSelector}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct Input { pub command: Option, pub mod_options: Option, - pub mod_id: Option, - pub mod_version: Option, + pub mod_id: Option, pub set_version: bool, pub all_lists: bool, pub clean: bool, @@ -61,8 +60,7 @@ impl Input { let mut command: Option = None; let mut mod_options: Option = None; - let mut mod_id: Option = None; - let mut mod_version: Option = None; + let mut mod_id: Option = None; let mut set_version = false; let mut all_lists = false; let mut clean = false; @@ -93,15 +91,17 @@ impl Input { command = Some(Cmd::Mod); mod_options = Some(ModOptions::Add); if arg_split.len() == 2 { - mod_id = Some(String::from(arg_split[1])); + mod_id = Some(IDSelector::ModificationID(String::from(arg_split[1]))); } else { return Err(MLError::new(ErrorType::ArgumentError, "Please specify a list mod slug or id")); } }, //TODO impl this "mv" => { + command = Some(Cmd::Mod); + mod_options = Some(ModOptions::Add); if arg_split.len() == 2 { - mod_version = Some(String::from(arg_split[1])); + mod_id = Some(IDSelector::VersionID(String::from(arg_split[1]))); } else { return Err(MLError::new(ErrorType::ArgumentError, "Please specify a version id")); }; @@ -110,7 +110,7 @@ impl Input { command = Some(Cmd::Mod); mod_options = Some(ModOptions::Remove); if arg_split.len() == 2 { - mod_id = Some(String::from(arg_split[1])); + mod_id = Some(IDSelector::ModificationID(String::from(arg_split[1]))); } else { return Err(MLError::new(ErrorType::ArgumentError, "Please specify a mod id")); }; @@ -206,7 +206,6 @@ impl Input { command, mod_options, mod_id, - mod_version, set_version, all_lists, clean, @@ -242,7 +241,7 @@ fn check_mod(mut input: Input, config: Cfg) -> MLE { }; match input.clone().mod_options.unwrap() { 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.mod_id.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)?); }; Ok(input) }, @@ -263,7 +262,7 @@ async 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"); - input.list_mcversion = Some(get_minecraft_version(config.apis.modrinth, MCVersionType::Release).await); + 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(); @@ -300,7 +299,6 @@ fn input_from() { command: Some(Cmd::List), mod_options: None, mod_id: None, - mod_version: None, set_version: false, all_lists: false, clean: false, @@ -327,8 +325,7 @@ async fn get_input_test() { Input { command: Some(Cmd::Mod), mod_options: Some(ModOptions::Add), - mod_id: Some(String::from("test")), - mod_version: None, + mod_id: Some(IDSelector::ModificationID(String::from("test"))), set_version: false, all_lists: false, clean: false, -- cgit v1.2.3