From 1890d59428dfcca861ea1b7820411d80cc60d713 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 22 Jan 2023 22:34:17 +0100 Subject: Added list version cmd, fixed some todos --- src/input.rs | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'src/input.rs') diff --git a/src/input.rs b/src/input.rs index be24660..a41f671 100644 --- a/src/input.rs +++ b/src/input.rs @@ -42,6 +42,7 @@ pub enum ListOptions { Add, Remove, Change, + Version, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -119,14 +120,18 @@ impl Input { "clean" => { clean = true; }, - "direct-download" => { - direct_download = true; + "no-download" => { + direct_download = false; }, "delete_old" => { delete_old = true; }, "l" => { - list = Some(lists_get(config.clone(), String::from(arg_split[1]))?); + if arg_split.len() == 2 { + list = Some(lists_get(config.clone(), String::from(arg_split[1]))?); + } else { + return Err(MLError::new(ErrorType::ArgumentError, "Please specify a list via it's id")); + } } "la" => { command = Some(Cmd::List); @@ -136,18 +141,26 @@ impl Input { "lr" => { command = Some(Cmd::List); list_options = Some(ListOptions::Remove); - 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); list_options = Some(ListOptions::Change); - list_id = Some(String::from(arg_split[1])); }, "lv" => { - list_mcversion = Some(String::from(arg_split[1])); + command = Some(Cmd::List); + list_options = Some(ListOptions::Version); + if arg_split.len() == 2 { + list_mcversion = Some(String::from(arg_split[1])); + } else { + return Err(MLError::new(ErrorType::ArgumentError, "Please specify a minecraft version")); + } + }, + "mcv" => { + if arg_split.len() == 2 { + list_mcversion = Some(String::from(arg_split[1])); + } else { + return Err(MLError::new(ErrorType::ArgumentError, "Please specify a minecraft version")); + } }, "ml" => { modloader = Some(Modloader::from(arg_split[1])?); @@ -199,7 +212,7 @@ 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), + Cmd::List => check_list(input, config), _ => Ok(input), } } @@ -223,7 +236,7 @@ fn check_mod(mut input: Input, config: Cfg) -> MLE { } } -fn check_list(mut input: Input) -> MLE { +fn check_list(mut input: Input, config: Cfg) -> MLE { if input.list_options.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_ARGUMENT")); }; @@ -240,12 +253,19 @@ fn check_list(mut input: Input) -> MLE { Ok(input) }, ListOptions::Remove => { - if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "LISTS_NO_ID")); }; + if input.list.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_SPECIFIED")); }; Ok(input) }, ListOptions::Change => { //TODO check if no change - if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "LISTS_NO_ID")); }; + if input.list.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_SPECIFIED")); }; + Ok(input) + }, + ListOptions::Version => { + if input.list.is_none() { + println!("No list specified, using default"); + input.list = Some(get_current_list(config)?); + }; Ok(input) } } -- cgit v1.2.3