From be9f74f4fb82b25abd99f7024e0f5eea2691f34f Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 18 Jan 2023 15:22:37 +0100 Subject: get plan in branch; "finished" input --- src/input.rs | 84 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 27 deletions(-) (limited to 'src/input.rs') diff --git a/src/input.rs b/src/input.rs index cdd3938..4e59c50 100644 --- a/src/input.rs +++ b/src/input.rs @@ -3,19 +3,17 @@ use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_ #[derive(Debug, Clone, PartialEq, Eq)] pub struct Input { pub command: Option, - pub download: bool, - pub update: bool, pub mod_options: Option, pub mod_id: Option, pub mod_version: Option, + pub set_version: bool, pub list: Option, pub list_options: Option, pub list_id: Option, pub list_mcversion: Option, pub modloader: Option, pub directory: Option, - pub export: bool, - pub import: bool, + pub io_options: Option, pub file: Option, } @@ -41,6 +39,12 @@ pub enum ListOptions { Change, } +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum IoOptions { + Export, + Import +} + impl Input { fn from(config: Cfg, input: Vec) -> MLE { let input_string = input.join(" "); @@ -51,19 +55,17 @@ impl Input { let mut command: Option = None; - let mut download = false; - let mut update = false; let mut mod_options: Option = None; let mut mod_id: Option = None; let mut mod_version: Option = None; + let mut set_version = false; let mut list: Option = None; let mut list_options: Option = None; let mut list_id: Option = None; let mut list_mcversion: Option = None; let mut modloader: Option = None; let mut directory: Option = None; - let mut export = false; - let mut import = false; + let mut io_options: Option = None; let mut file: Option = None; for arg in args { @@ -75,11 +77,28 @@ impl Input { }, "u" | "update" => { command = Some(Cmd::Update); - } + }, "ma" => { command = Some(Cmd::Mod); mod_options = Some(ModOptions::Add); - mod_id = Some(String::from(arg_split[1])); + if arg_split.len() != 1 { + mod_id = Some(String::from(arg_split[1])); + } + }, + "mr" => { + command = Some(Cmd::Mod); + mod_options = Some(ModOptions::Remove); + if arg_split.len() != 1 { + mod_id = Some(String::from(arg_split[1])); + } + }, + "mv" => { + if arg_split.len() != 1 { + mod_version = Some(String::from(arg_split[1])); + }; + }, + "set-version" => { + set_version = true; }, "l" => { list = Some(lists_get(config.clone(), String::from(arg_split[1]))?); @@ -101,26 +120,41 @@ impl Input { }, "lv" => { list_mcversion = Some(String::from(arg_split[1])); - } + }, + "ml" => { + modloader = Some(Modloader::from(arg_split[1])?); + }, + "dir" => { + directory = Some(String::from(arg_split[1])); + }, + "export" => { + command = Some(Cmd::Io); + io_options = Some(IoOptions::Export); + }, + "import" => { + command = Some(Cmd::Io); + io_options = Some(IoOptions::Import); + }, + "f" => { + file = Some(String::from(arg_split[1])); + }, _ => return Err(MLError::new(ErrorType::ArgumentError, "UnknownArgument")), } } Ok(Self { command, - download, - update, mod_options, mod_id, mod_version, + set_version, list, list_options, list_id, list_mcversion, modloader, directory, - export, - import, + io_options, file }) } @@ -153,20 +187,20 @@ pub async fn get_input(config: Cfg, args: Vec) -> MLE { } } +//Move checks to commands? translate to variables there? fn check_mod(mut input: Input, config: Cfg) -> MLE { - print!("Checkmod"); if input.mod_options.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "NO_MOD_ARGUMENT")); }; match input.clone().mod_options.unwrap() { + //Check for MV if no mod-id on both ModOptions::Add => { - print!("Checkadd"); - if input.mod_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID")); }; + if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID_MODVERSION")); }; if input.list_id.is_none() { println!("NOLIST"); input.list = Some(get_current_list(config.clone())?); }; Ok(input) }, ModOptions::Remove => { - if input.mod_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID")); }; + if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID_MODVERSION")); }; Ok(input) }, } @@ -215,19 +249,17 @@ fn input_from() { Input::from(config.clone(), vec![String::from("-la test -lv 1.19.3")]).unwrap(), Input { command: Some(Cmd::List), - download: false, - update: false, mod_options: None, mod_id: None, mod_version: None, + set_version: false, list: None, list_options: Some(ListOptions::Add), list_id: Some(String::from("test")), list_mcversion: Some(String::from("1.19.3")), modloader: None, directory: None, - export: false, - import: false, + io_options: None, file: None } ); @@ -241,19 +273,17 @@ async fn get_input_test() { get_input(config.clone(), vec![String::from("-ma test")]).await.unwrap(), Input { command: Some(Cmd::Mod), - download: false, - update: false, mod_options: Some(ModOptions::Add), mod_id: Some(String::from("test")), mod_version: None, + set_version: false, list: Some(lists_get(config.clone(), String::from("one")).unwrap()), list_options: None, list_id: None, list_mcversion: None, modloader: None, directory: None, - export: false, - import: false, + io_options: None, file: None } ) -- cgit v1.2.3