From ddde9204c72dd867f920f07f6483be03dda7cf68 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 28 Nov 2022 22:55:14 +0100 Subject: basically update impl; added "good" download; auto dl on new mod; db to 0.4; etc --- src/input.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/input.rs') diff --git a/src/input.rs b/src/input.rs index 0946971..b2b4f1b 100644 --- a/src/input.rs +++ b/src/input.rs @@ -10,6 +10,7 @@ pub struct Input { pub all_lists: bool, pub delete_old: bool, pub clean: bool, + pub disable_download: bool, } impl Input { @@ -20,7 +21,9 @@ impl Input { let mut all_lists = false; let mut delete_old = false; let mut clean = false; - + let mut disable_download = false; + + let mut toremove: Vec = vec![]; for (i, input) in split.clone().into_iter().enumerate() { if input.starts_with("--") { match input { @@ -28,12 +31,17 @@ impl Input { "--all-lists" => all_lists = true, "--delete-old" => delete_old = true, "--clean" => clean = true, + "--disable-download" => disable_download = true, _ => continue, } - split.remove(i); + toremove.push(i) } } + for rem in toremove.into_iter().rev() { + split.remove(rem); + } + let command = Cmd::from(split.remove(0))?; let subcommand = match split.is_empty() { false => Some(Subcmd::from(split.remove(0))?), @@ -51,7 +59,7 @@ impl Input { } }; - Ok(Self { command, subcommand, args, direct_download, all_lists, delete_old, clean }) + Ok(Self { command, subcommand, args, direct_download, all_lists, delete_old, clean, disable_download }) } } @@ -127,6 +135,11 @@ pub async fn get_input(config: Cfg) -> Result<(), Box> { #[test] fn input_from() { let string = "list add test 1.19.2 fabric"; - let input = Input{ command: Cmd::List, subcommand: Some(Subcmd::Add), args: Some(vec![String::from("test"), String::from("1.19.2"), String::from("fabric")]), direct_download: false, all_lists: false, clean: false, delete_old: false }; + let input = Input{ command: Cmd::List, subcommand: Some(Subcmd::Add), args: Some(vec![String::from("test"), String::from("1.19.2"), String::from("fabric")]), direct_download: false, all_lists: false, clean: false, delete_old: false, disable_download: false }; + assert_eq!(Input::from(string).unwrap(), input); + + let string = "update --direct-download --delete-old"; + let input = Input{ command: Cmd::Update, subcommand: None, args: None, direct_download: true, all_lists: false, clean: false, delete_old: true, disable_download: false }; assert_eq!(Input::from(string).unwrap(), input); + } -- cgit v1.2.3