diff options
Diffstat (limited to 'src/input.rs')
-rw-r--r-- | src/input.rs | 21 |
1 files changed, 17 insertions, 4 deletions
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 { | |||
10 | pub all_lists: bool, | 10 | pub all_lists: bool, |
11 | pub delete_old: bool, | 11 | pub delete_old: bool, |
12 | pub clean: bool, | 12 | pub clean: bool, |
13 | pub disable_download: bool, | ||
13 | } | 14 | } |
14 | 15 | ||
15 | impl Input { | 16 | impl Input { |
@@ -20,7 +21,9 @@ impl Input { | |||
20 | let mut all_lists = false; | 21 | let mut all_lists = false; |
21 | let mut delete_old = false; | 22 | let mut delete_old = false; |
22 | let mut clean = false; | 23 | let mut clean = false; |
23 | 24 | let mut disable_download = false; | |
25 | |||
26 | let mut toremove: Vec<usize> = vec![]; | ||
24 | for (i, input) in split.clone().into_iter().enumerate() { | 27 | for (i, input) in split.clone().into_iter().enumerate() { |
25 | if input.starts_with("--") { | 28 | if input.starts_with("--") { |
26 | match input { | 29 | match input { |
@@ -28,12 +31,17 @@ impl Input { | |||
28 | "--all-lists" => all_lists = true, | 31 | "--all-lists" => all_lists = true, |
29 | "--delete-old" => delete_old = true, | 32 | "--delete-old" => delete_old = true, |
30 | "--clean" => clean = true, | 33 | "--clean" => clean = true, |
34 | "--disable-download" => disable_download = true, | ||
31 | _ => continue, | 35 | _ => continue, |
32 | } | 36 | } |
33 | split.remove(i); | 37 | toremove.push(i) |
34 | } | 38 | } |
35 | } | 39 | } |
36 | 40 | ||
41 | for rem in toremove.into_iter().rev() { | ||
42 | split.remove(rem); | ||
43 | } | ||
44 | |||
37 | let command = Cmd::from(split.remove(0))?; | 45 | let command = Cmd::from(split.remove(0))?; |
38 | let subcommand = match split.is_empty() { | 46 | let subcommand = match split.is_empty() { |
39 | false => Some(Subcmd::from(split.remove(0))?), | 47 | false => Some(Subcmd::from(split.remove(0))?), |
@@ -51,7 +59,7 @@ impl Input { | |||
51 | } | 59 | } |
52 | }; | 60 | }; |
53 | 61 | ||
54 | Ok(Self { command, subcommand, args, direct_download, all_lists, delete_old, clean }) | 62 | Ok(Self { command, subcommand, args, direct_download, all_lists, delete_old, clean, disable_download }) |
55 | } | 63 | } |
56 | } | 64 | } |
57 | 65 | ||
@@ -127,6 +135,11 @@ pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | |||
127 | #[test] | 135 | #[test] |
128 | fn input_from() { | 136 | fn input_from() { |
129 | let string = "list add test 1.19.2 fabric"; | 137 | let string = "list add test 1.19.2 fabric"; |
130 | 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 }; | 138 | 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 }; |
139 | assert_eq!(Input::from(string).unwrap(), input); | ||
140 | |||
141 | let string = "update --direct-download --delete-old"; | ||
142 | let input = Input{ command: Cmd::Update, subcommand: None, args: None, direct_download: true, all_lists: false, clean: false, delete_old: true, disable_download: false }; | ||
131 | assert_eq!(Input::from(string).unwrap(), input); | 143 | assert_eq!(Input::from(string).unwrap(), input); |
144 | |||
132 | } | 145 | } |