From f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 19 Jan 2023 18:37:42 +0100 Subject: input mostly inplemented, mods missing --- src/input.rs | 115 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 49 deletions(-) (limited to 'src/input.rs') diff --git a/src/input.rs b/src/input.rs index 4e59c50..be24660 100644 --- a/src/input.rs +++ b/src/input.rs @@ -7,6 +7,10 @@ pub struct Input { pub mod_id: Option, pub mod_version: Option, pub set_version: bool, + pub all_lists: bool, + pub clean: bool, + pub direct_download: bool, + pub delete_old: bool, pub list: Option, pub list_options: Option, pub list_id: Option, @@ -24,6 +28,7 @@ pub enum Cmd { Update, Download, Io, + Version, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -59,6 +64,10 @@ impl Input { let mut mod_id: Option = None; let mut mod_version: Option = None; let mut set_version = false; + let mut all_lists = false; + let mut clean = false; + let mut direct_download = true; + let mut delete_old = false; let mut list: Option = None; let mut list_options: Option = None; let mut list_id: Option = None; @@ -71,7 +80,9 @@ impl Input { for arg in args { let arg_split: Vec<&str> = arg.trim().split(" ").collect(); match arg_split[0] { - "v" | "version" => { show_version(); }, + "v" | "version" => { + command = Some(Cmd::Version); + }, "d" | "download" => { command = Some(Cmd::Download); }, @@ -81,25 +92,39 @@ impl Input { "ma" => { command = Some(Cmd::Mod); mod_options = Some(ModOptions::Add); - if arg_split.len() != 1 { + if arg_split.len() == 2 { mod_id = Some(String::from(arg_split[1])); } }, + "mv" => { + command = Some(Cmd::Mod); + mod_options = Some(ModOptions::Add); + if arg_split.len() == 2 { + mod_version = Some(String::from(arg_split[1])); + }; + }, "mr" => { command = Some(Cmd::Mod); mod_options = Some(ModOptions::Remove); - if arg_split.len() != 1 { + if arg_split.len() == 2 { 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" => { set_version = true; }, + "all_lists" => { + all_lists = true; + }, + "clean" => { + clean = true; + }, + "direct-download" => { + direct_download = true; + }, + "delete_old" => { + delete_old = true; + }, "l" => { list = Some(lists_get(config.clone(), String::from(arg_split[1]))?); } @@ -111,7 +136,10 @@ impl Input { "lr" => { command = Some(Cmd::List); list_options = Some(ListOptions::Remove); - list_id = Some(String::from(arg_split[1])); + if arg_split.len() == 2 { + list_id = Some(String::from(arg_split[1])); + list = Some(lists_get(config.clone(), list_id.clone().unwrap())?) + } }, "lc" => { command = Some(Cmd::List); @@ -138,7 +166,7 @@ impl Input { "f" => { file = Some(String::from(arg_split[1])); }, - _ => return Err(MLError::new(ErrorType::ArgumentError, "UnknownArgument")), + _ => return Err(MLError::new(ErrorType::ArgumentError, format!("Unknown Argument ({})", arg_split[0]).as_str())), } } @@ -148,6 +176,10 @@ impl Input { mod_id, mod_version, set_version, + all_lists, + clean, + direct_download, + delete_old, list, list_options, list_id, @@ -160,47 +192,32 @@ impl Input { } } -fn show_version() { - match std::env::var("DEV") { - Ok(dev) => { - let devint = dev.parse::().unwrap(); - if devint >= 1 { - println!("Modlist by FxQnLr v{} (DEV)", env!("CARGO_PKG_VERSION")); - } else { - println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")); - } - }, - Err(..) => println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")), - } - std::process::exit(0); -} - pub async fn get_input(config: Cfg, args: Vec) -> MLE { let input = Input::from(config.clone(), args)?; - + + if input.command.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No command specified")); }; + match input.clone().command.unwrap() { Cmd::Mod => check_mod(input, config), Cmd::List => check_list(input), - Cmd::Update => check_update(input), - Cmd::Download => check_download(input), - Cmd::Io => check_io(input), + _ => 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_ARGUMENT")); + 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, "MODS_NO_MODID_MODVERSION")); }; - if input.list_id.is_none() { println!("NOLIST"); input.list = Some(get_current_list(config.clone())?); }; + 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())?); }; Ok(input) }, ModOptions::Remove => { - if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID_MODVERSION")); }; + if input.mod_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID")); }; Ok(input) }, } @@ -212,9 +229,13 @@ fn check_list(mut input: Input) -> MLE { }; match input.clone().list_options.unwrap() { ListOptions::Add => { - if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "LISTS_NO_ID")); }; - if input.list_mcversion.is_none() { /*TODO Get latest version */ input.list_mcversion = Some(String::from("1.19.3")) }; - if input.modloader.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "LISTS_NO_MODLOADER")); }; + 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")); + }; + 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) }, @@ -230,18 +251,6 @@ fn check_list(mut input: Input) -> MLE { } } -fn check_update(input: Input) -> MLE { - Ok(input) -} - -fn check_download(input: Input) -> MLE { - Ok(input) -} - -fn check_io(input: Input) -> MLE { - Ok(input) -} - #[test] fn input_from() { let config = Cfg::init("modlist.toml").unwrap(); @@ -253,6 +262,10 @@ fn input_from() { mod_id: None, mod_version: None, set_version: false, + all_lists: false, + clean: false, + direct_download: false, + delete_old: false, list: None, list_options: Some(ListOptions::Add), list_id: Some(String::from("test")), @@ -277,6 +290,10 @@ async fn get_input_test() { mod_id: Some(String::from("test")), mod_version: None, set_version: false, + all_lists: false, + clean: false, + direct_download: false, + delete_old: false, list: Some(lists_get(config.clone(), String::from("one")).unwrap()), list_options: None, list_id: None, -- cgit v1.2.3