diff options
Diffstat (limited to 'src/input.rs')
-rw-r--r-- | src/input.rs | 84 |
1 files changed, 57 insertions, 27 deletions
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_ | |||
3 | #[derive(Debug, Clone, PartialEq, Eq)] | 3 | #[derive(Debug, Clone, PartialEq, Eq)] |
4 | pub struct Input { | 4 | pub struct Input { |
5 | pub command: Option<Cmd>, | 5 | pub command: Option<Cmd>, |
6 | pub download: bool, | ||
7 | pub update: bool, | ||
8 | pub mod_options: Option<ModOptions>, | 6 | pub mod_options: Option<ModOptions>, |
9 | pub mod_id: Option<String>, | 7 | pub mod_id: Option<String>, |
10 | pub mod_version: Option<String>, | 8 | pub mod_version: Option<String>, |
9 | pub set_version: bool, | ||
11 | pub list: Option<List>, | 10 | pub list: Option<List>, |
12 | pub list_options: Option<ListOptions>, | 11 | pub list_options: Option<ListOptions>, |
13 | pub list_id: Option<String>, | 12 | pub list_id: Option<String>, |
14 | pub list_mcversion: Option<String>, | 13 | pub list_mcversion: Option<String>, |
15 | pub modloader: Option<Modloader>, | 14 | pub modloader: Option<Modloader>, |
16 | pub directory: Option<String>, | 15 | pub directory: Option<String>, |
17 | pub export: bool, | 16 | pub io_options: Option<IoOptions>, |
18 | pub import: bool, | ||
19 | pub file: Option<String>, | 17 | pub file: Option<String>, |
20 | } | 18 | } |
21 | 19 | ||
@@ -41,6 +39,12 @@ pub enum ListOptions { | |||
41 | Change, | 39 | Change, |
42 | } | 40 | } |
43 | 41 | ||
42 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
43 | pub enum IoOptions { | ||
44 | Export, | ||
45 | Import | ||
46 | } | ||
47 | |||
44 | impl Input { | 48 | impl Input { |
45 | fn from(config: Cfg, input: Vec<String>) -> MLE<Self> { | 49 | fn from(config: Cfg, input: Vec<String>) -> MLE<Self> { |
46 | let input_string = input.join(" "); | 50 | let input_string = input.join(" "); |
@@ -51,19 +55,17 @@ impl Input { | |||
51 | 55 | ||
52 | let mut command: Option<Cmd> = None; | 56 | let mut command: Option<Cmd> = None; |
53 | 57 | ||
54 | let mut download = false; | ||
55 | let mut update = false; | ||
56 | let mut mod_options: Option<ModOptions> = None; | 58 | let mut mod_options: Option<ModOptions> = None; |
57 | let mut mod_id: Option<String> = None; | 59 | let mut mod_id: Option<String> = None; |
58 | let mut mod_version: Option<String> = None; | 60 | let mut mod_version: Option<String> = None; |
61 | let mut set_version = false; | ||
59 | let mut list: Option<List> = None; | 62 | let mut list: Option<List> = None; |
60 | let mut list_options: Option<ListOptions> = None; | 63 | let mut list_options: Option<ListOptions> = None; |
61 | let mut list_id: Option<String> = None; | 64 | let mut list_id: Option<String> = None; |
62 | let mut list_mcversion: Option<String> = None; | 65 | let mut list_mcversion: Option<String> = None; |
63 | let mut modloader: Option<Modloader> = None; | 66 | let mut modloader: Option<Modloader> = None; |
64 | let mut directory: Option<String> = None; | 67 | let mut directory: Option<String> = None; |
65 | let mut export = false; | 68 | let mut io_options: Option<IoOptions> = None; |
66 | let mut import = false; | ||
67 | let mut file: Option<String> = None; | 69 | let mut file: Option<String> = None; |
68 | 70 | ||
69 | for arg in args { | 71 | for arg in args { |
@@ -75,11 +77,28 @@ impl Input { | |||
75 | }, | 77 | }, |
76 | "u" | "update" => { | 78 | "u" | "update" => { |
77 | command = Some(Cmd::Update); | 79 | command = Some(Cmd::Update); |
78 | } | 80 | }, |
79 | "ma" => { | 81 | "ma" => { |
80 | command = Some(Cmd::Mod); | 82 | command = Some(Cmd::Mod); |
81 | mod_options = Some(ModOptions::Add); | 83 | mod_options = Some(ModOptions::Add); |
82 | mod_id = Some(String::from(arg_split[1])); | 84 | if arg_split.len() != 1 { |
85 | mod_id = Some(String::from(arg_split[1])); | ||
86 | } | ||
87 | }, | ||
88 | "mr" => { | ||
89 | command = Some(Cmd::Mod); | ||
90 | mod_options = Some(ModOptions::Remove); | ||
91 | if arg_split.len() != 1 { | ||
92 | mod_id = Some(String::from(arg_split[1])); | ||
93 | } | ||
94 | }, | ||
95 | "mv" => { | ||
96 | if arg_split.len() != 1 { | ||
97 | mod_version = Some(String::from(arg_split[1])); | ||
98 | }; | ||
99 | }, | ||
100 | "set-version" => { | ||
101 | set_version = true; | ||
83 | }, | 102 | }, |
84 | "l" => { | 103 | "l" => { |
85 | list = Some(lists_get(config.clone(), String::from(arg_split[1]))?); | 104 | list = Some(lists_get(config.clone(), String::from(arg_split[1]))?); |
@@ -101,26 +120,41 @@ impl Input { | |||
101 | }, | 120 | }, |
102 | "lv" => { | 121 | "lv" => { |
103 | list_mcversion = Some(String::from(arg_split[1])); | 122 | list_mcversion = Some(String::from(arg_split[1])); |
104 | } | 123 | }, |
124 | "ml" => { | ||
125 | modloader = Some(Modloader::from(arg_split[1])?); | ||
126 | }, | ||
127 | "dir" => { | ||
128 | directory = Some(String::from(arg_split[1])); | ||
129 | }, | ||
130 | "export" => { | ||
131 | command = Some(Cmd::Io); | ||
132 | io_options = Some(IoOptions::Export); | ||
133 | }, | ||
134 | "import" => { | ||
135 | command = Some(Cmd::Io); | ||
136 | io_options = Some(IoOptions::Import); | ||
137 | }, | ||
138 | "f" => { | ||
139 | file = Some(String::from(arg_split[1])); | ||
140 | }, | ||
105 | _ => return Err(MLError::new(ErrorType::ArgumentError, "UnknownArgument")), | 141 | _ => return Err(MLError::new(ErrorType::ArgumentError, "UnknownArgument")), |
106 | } | 142 | } |
107 | } | 143 | } |
108 | 144 | ||
109 | Ok(Self { | 145 | Ok(Self { |
110 | command, | 146 | command, |
111 | download, | ||
112 | update, | ||
113 | mod_options, | 147 | mod_options, |
114 | mod_id, | 148 | mod_id, |
115 | mod_version, | 149 | mod_version, |
150 | set_version, | ||
116 | list, | 151 | list, |
117 | list_options, | 152 | list_options, |
118 | list_id, | 153 | list_id, |
119 | list_mcversion, | 154 | list_mcversion, |
120 | modloader, | 155 | modloader, |
121 | directory, | 156 | directory, |
122 | export, | 157 | io_options, |
123 | import, | ||
124 | file | 158 | file |
125 | }) | 159 | }) |
126 | } | 160 | } |
@@ -153,20 +187,20 @@ pub async fn get_input(config: Cfg, args: Vec<String>) -> MLE<Input> { | |||
153 | } | 187 | } |
154 | } | 188 | } |
155 | 189 | ||
190 | //Move checks to commands? translate to variables there? | ||
156 | fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> { | 191 | fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> { |
157 | print!("Checkmod"); | ||
158 | if input.mod_options.is_none() { | 192 | if input.mod_options.is_none() { |
159 | return Err(MLError::new(ErrorType::ArgumentError, "NO_MOD_ARGUMENT")); | 193 | return Err(MLError::new(ErrorType::ArgumentError, "NO_MOD_ARGUMENT")); |
160 | }; | 194 | }; |
161 | match input.clone().mod_options.unwrap() { | 195 | match input.clone().mod_options.unwrap() { |
196 | //Check for MV if no mod-id on both | ||
162 | ModOptions::Add => { | 197 | ModOptions::Add => { |
163 | print!("Checkadd"); | 198 | if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID_MODVERSION")); }; |
164 | if input.mod_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID")); }; | ||
165 | if input.list_id.is_none() { println!("NOLIST"); input.list = Some(get_current_list(config.clone())?); }; | 199 | if input.list_id.is_none() { println!("NOLIST"); input.list = Some(get_current_list(config.clone())?); }; |
166 | Ok(input) | 200 | Ok(input) |
167 | }, | 201 | }, |
168 | ModOptions::Remove => { | 202 | ModOptions::Remove => { |
169 | if input.mod_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID")); }; | 203 | if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID_MODVERSION")); }; |
170 | Ok(input) | 204 | Ok(input) |
171 | }, | 205 | }, |
172 | } | 206 | } |
@@ -215,19 +249,17 @@ fn input_from() { | |||
215 | Input::from(config.clone(), vec![String::from("-la test -lv 1.19.3")]).unwrap(), | 249 | Input::from(config.clone(), vec![String::from("-la test -lv 1.19.3")]).unwrap(), |
216 | Input { | 250 | Input { |
217 | command: Some(Cmd::List), | 251 | command: Some(Cmd::List), |
218 | download: false, | ||
219 | update: false, | ||
220 | mod_options: None, | 252 | mod_options: None, |
221 | mod_id: None, | 253 | mod_id: None, |
222 | mod_version: None, | 254 | mod_version: None, |
255 | set_version: false, | ||
223 | list: None, | 256 | list: None, |
224 | list_options: Some(ListOptions::Add), | 257 | list_options: Some(ListOptions::Add), |
225 | list_id: Some(String::from("test")), | 258 | list_id: Some(String::from("test")), |
226 | list_mcversion: Some(String::from("1.19.3")), | 259 | list_mcversion: Some(String::from("1.19.3")), |
227 | modloader: None, | 260 | modloader: None, |
228 | directory: None, | 261 | directory: None, |
229 | export: false, | 262 | io_options: None, |
230 | import: false, | ||
231 | file: None | 263 | file: None |
232 | } | 264 | } |
233 | ); | 265 | ); |
@@ -241,19 +273,17 @@ async fn get_input_test() { | |||
241 | get_input(config.clone(), vec![String::from("-ma test")]).await.unwrap(), | 273 | get_input(config.clone(), vec![String::from("-ma test")]).await.unwrap(), |
242 | Input { | 274 | Input { |
243 | command: Some(Cmd::Mod), | 275 | command: Some(Cmd::Mod), |
244 | download: false, | ||
245 | update: false, | ||
246 | mod_options: Some(ModOptions::Add), | 276 | mod_options: Some(ModOptions::Add), |
247 | mod_id: Some(String::from("test")), | 277 | mod_id: Some(String::from("test")), |
248 | mod_version: None, | 278 | mod_version: None, |
279 | set_version: false, | ||
249 | list: Some(lists_get(config.clone(), String::from("one")).unwrap()), | 280 | list: Some(lists_get(config.clone(), String::from("one")).unwrap()), |
250 | list_options: None, | 281 | list_options: None, |
251 | list_id: None, | 282 | list_id: None, |
252 | list_mcversion: None, | 283 | list_mcversion: None, |
253 | modloader: None, | 284 | modloader: None, |
254 | directory: None, | 285 | directory: None, |
255 | export: false, | 286 | io_options: None, |
256 | import: false, | ||
257 | file: None | 287 | file: None |
258 | } | 288 | } |
259 | ) | 289 | ) |