diff options
Diffstat (limited to 'src/input.rs')
-rw-r--r-- | src/input.rs | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/input.rs b/src/input.rs index 17fc773..6c62ab7 100644 --- a/src/input.rs +++ b/src/input.rs | |||
@@ -1,11 +1,10 @@ | |||
1 | use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_get, get_current_list, List, modrinth::{get_minecraft_version, MCVersionType}}; | 1 | use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_get, get_current_list, List, modrinth::{get_minecraft_version, MCVersionType}, IDSelector}; |
2 | 2 | ||
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 mod_options: Option<ModOptions>, | 6 | pub mod_options: Option<ModOptions>, |
7 | pub mod_id: Option<String>, | 7 | pub mod_id: Option<IDSelector>, |
8 | pub mod_version: Option<String>, | ||
9 | pub set_version: bool, | 8 | pub set_version: bool, |
10 | pub all_lists: bool, | 9 | pub all_lists: bool, |
11 | pub clean: bool, | 10 | pub clean: bool, |
@@ -61,8 +60,7 @@ impl Input { | |||
61 | let mut command: Option<Cmd> = None; | 60 | let mut command: Option<Cmd> = None; |
62 | 61 | ||
63 | let mut mod_options: Option<ModOptions> = None; | 62 | let mut mod_options: Option<ModOptions> = None; |
64 | let mut mod_id: Option<String> = None; | 63 | let mut mod_id: Option<IDSelector> = None; |
65 | let mut mod_version: Option<String> = None; | ||
66 | let mut set_version = false; | 64 | let mut set_version = false; |
67 | let mut all_lists = false; | 65 | let mut all_lists = false; |
68 | let mut clean = false; | 66 | let mut clean = false; |
@@ -93,15 +91,17 @@ impl Input { | |||
93 | command = Some(Cmd::Mod); | 91 | command = Some(Cmd::Mod); |
94 | mod_options = Some(ModOptions::Add); | 92 | mod_options = Some(ModOptions::Add); |
95 | if arg_split.len() == 2 { | 93 | if arg_split.len() == 2 { |
96 | mod_id = Some(String::from(arg_split[1])); | 94 | mod_id = Some(IDSelector::ModificationID(String::from(arg_split[1]))); |
97 | } else { | 95 | } else { |
98 | return Err(MLError::new(ErrorType::ArgumentError, "Please specify a list mod slug or id")); | 96 | return Err(MLError::new(ErrorType::ArgumentError, "Please specify a list mod slug or id")); |
99 | } | 97 | } |
100 | }, | 98 | }, |
101 | //TODO impl this | 99 | //TODO impl this |
102 | "mv" => { | 100 | "mv" => { |
101 | command = Some(Cmd::Mod); | ||
102 | mod_options = Some(ModOptions::Add); | ||
103 | if arg_split.len() == 2 { | 103 | if arg_split.len() == 2 { |
104 | mod_version = Some(String::from(arg_split[1])); | 104 | mod_id = Some(IDSelector::VersionID(String::from(arg_split[1]))); |
105 | } else { | 105 | } else { |
106 | return Err(MLError::new(ErrorType::ArgumentError, "Please specify a version id")); | 106 | return Err(MLError::new(ErrorType::ArgumentError, "Please specify a version id")); |
107 | }; | 107 | }; |
@@ -110,7 +110,7 @@ impl Input { | |||
110 | command = Some(Cmd::Mod); | 110 | command = Some(Cmd::Mod); |
111 | mod_options = Some(ModOptions::Remove); | 111 | mod_options = Some(ModOptions::Remove); |
112 | if arg_split.len() == 2 { | 112 | if arg_split.len() == 2 { |
113 | mod_id = Some(String::from(arg_split[1])); | 113 | mod_id = Some(IDSelector::ModificationID(String::from(arg_split[1]))); |
114 | } else { | 114 | } else { |
115 | return Err(MLError::new(ErrorType::ArgumentError, "Please specify a mod id")); | 115 | return Err(MLError::new(ErrorType::ArgumentError, "Please specify a mod id")); |
116 | }; | 116 | }; |
@@ -206,7 +206,6 @@ impl Input { | |||
206 | command, | 206 | command, |
207 | mod_options, | 207 | mod_options, |
208 | mod_id, | 208 | mod_id, |
209 | mod_version, | ||
210 | set_version, | 209 | set_version, |
211 | all_lists, | 210 | all_lists, |
212 | clean, | 211 | clean, |
@@ -242,7 +241,7 @@ fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> { | |||
242 | }; | 241 | }; |
243 | match input.clone().mod_options.unwrap() { | 242 | match input.clone().mod_options.unwrap() { |
244 | ModOptions::Add => { | 243 | ModOptions::Add => { |
245 | if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No mod id/slug or version id")); }; | 244 | if input.mod_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No mod id/slug or version id")); }; |
246 | if input.list_id.is_none() { input.list = Some(get_current_list(config)?); }; | 245 | if input.list_id.is_none() { input.list = Some(get_current_list(config)?); }; |
247 | Ok(input) | 246 | Ok(input) |
248 | }, | 247 | }, |
@@ -263,7 +262,7 @@ async fn check_list(mut input: Input, config: Cfg) -> MLE<Input> { | |||
263 | if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no list id specified")); }; | 262 | if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no list id specified")); }; |
264 | if input.list_mcversion.is_none() { | 263 | if input.list_mcversion.is_none() { |
265 | println!("No Minecraft Version specified, defaulting to latest release"); | 264 | println!("No Minecraft Version specified, defaulting to latest release"); |
266 | input.list_mcversion = Some(get_minecraft_version(config.apis.modrinth, MCVersionType::Release).await); | 265 | input.list_mcversion = Some(get_minecraft_version(&config.apis.modrinth, MCVersionType::Release).await); |
267 | }; | 266 | }; |
268 | if input.directory.is_none() { | 267 | if input.directory.is_none() { |
269 | let id = input.clone().list_id.unwrap(); | 268 | let id = input.clone().list_id.unwrap(); |
@@ -300,7 +299,6 @@ fn input_from() { | |||
300 | command: Some(Cmd::List), | 299 | command: Some(Cmd::List), |
301 | mod_options: None, | 300 | mod_options: None, |
302 | mod_id: None, | 301 | mod_id: None, |
303 | mod_version: None, | ||
304 | set_version: false, | 302 | set_version: false, |
305 | all_lists: false, | 303 | all_lists: false, |
306 | clean: false, | 304 | clean: false, |
@@ -327,8 +325,7 @@ async fn get_input_test() { | |||
327 | Input { | 325 | Input { |
328 | command: Some(Cmd::Mod), | 326 | command: Some(Cmd::Mod), |
329 | mod_options: Some(ModOptions::Add), | 327 | mod_options: Some(ModOptions::Add), |
330 | mod_id: Some(String::from("test")), | 328 | mod_id: Some(IDSelector::ModificationID(String::from("test"))), |
331 | mod_version: None, | ||
332 | set_version: false, | 329 | set_version: false, |
333 | all_lists: false, | 330 | all_lists: false, |
334 | clean: false, | 331 | clean: false, |