summaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-01-26 17:23:06 +0100
committerfxqnlr <[email protected]>2023-01-26 17:23:06 +0100
commit57ab6addda10a49c18dc09208dfb319c0205e869 (patch)
treeeec6fd465a113d15c819c64a94bc04d425f0e842 /src/input.rs
parent1890d59428dfcca861ea1b7820411d80cc60d713 (diff)
downloadmodlist-57ab6addda10a49c18dc09208dfb319c0205e869.tar
modlist-57ab6addda10a49c18dc09208dfb319c0205e869.tar.gz
modlist-57ab6addda10a49c18dc09208dfb319c0205e869.zip
Todos; fixed input with "-"
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/input.rs b/src/input.rs
index a41f671..144f22a 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -1,4 +1,4 @@
1use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_get, get_current_list, List}; 1use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_get, get_current_list, List, modrinth::{get_minecraft_version, MCVersionType}};
2 2
3#[derive(Debug, Clone, PartialEq, Eq)] 3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct Input { 4pub struct Input {
@@ -54,10 +54,8 @@ pub enum IoOptions {
54impl Input { 54impl Input {
55 fn from(config: Cfg, input: Vec<String>) -> MLE<Self> { 55 fn from(config: Cfg, input: Vec<String>) -> MLE<Self> {
56 let input_string = input.join(" "); 56 let input_string = input.join(" ");
57 let mut args: Vec<&str> = input_string.split('-').collect(); 57 let mut args: Vec<&str> = input_string.split(" -").collect();
58 args.reverse(); 58 args[0] = args[0].split_at(1).1;
59 args.pop();
60 args.reverse();
61 59
62 let mut command: Option<Cmd> = None; 60 let mut command: Option<Cmd> = None;
63 61
@@ -95,6 +93,8 @@ impl Input {
95 mod_options = Some(ModOptions::Add); 93 mod_options = Some(ModOptions::Add);
96 if arg_split.len() == 2 { 94 if arg_split.len() == 2 {
97 mod_id = Some(String::from(arg_split[1])); 95 mod_id = Some(String::from(arg_split[1]));
96 } else {
97 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a list mod slug or id"));
98 } 98 }
99 }, 99 },
100 "mv" => { 100 "mv" => {
@@ -102,6 +102,8 @@ impl Input {
102 mod_options = Some(ModOptions::Add); 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_version = Some(String::from(arg_split[1]));
105 } else {
106 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a version id"));
105 }; 107 };
106 }, 108 },
107 "mr" => { 109 "mr" => {
@@ -109,7 +111,9 @@ impl Input {
109 mod_options = Some(ModOptions::Remove); 111 mod_options = Some(ModOptions::Remove);
110 if arg_split.len() == 2 { 112 if arg_split.len() == 2 {
111 mod_id = Some(String::from(arg_split[1])); 113 mod_id = Some(String::from(arg_split[1]));
112 } 114 } else {
115 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a mod id"));
116 };
113 }, 117 },
114 "set_version" => { 118 "set_version" => {
115 set_version = true; 119 set_version = true;
@@ -120,7 +124,7 @@ impl Input {
120 "clean" => { 124 "clean" => {
121 clean = true; 125 clean = true;
122 }, 126 },
123 "no-download" => { 127 "no_download" => {
124 direct_download = false; 128 direct_download = false;
125 }, 129 },
126 "delete_old" => { 130 "delete_old" => {
@@ -136,7 +140,11 @@ impl Input {
136 "la" => { 140 "la" => {
137 command = Some(Cmd::List); 141 command = Some(Cmd::List);
138 list_options = Some(ListOptions::Add); 142 list_options = Some(ListOptions::Add);
139 list_id = Some(String::from(arg_split[1])); 143 if arg_split.len() == 2 {
144 list_id = Some(String::from(arg_split[1]));
145 } else {
146 return Err(MLError::new(ErrorType::ArgumentError, "Please give the new list an id"));
147 }
140 }, 148 },
141 "lr" => { 149 "lr" => {
142 command = Some(Cmd::List); 150 command = Some(Cmd::List);
@@ -163,10 +171,18 @@ impl Input {
163 } 171 }
164 }, 172 },
165 "ml" => { 173 "ml" => {
166 modloader = Some(Modloader::from(arg_split[1])?); 174 if arg_split.len() == 2 {
175 modloader = Some(Modloader::from(arg_split[1])?);
176 } else {
177 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a modloader"));
178 }
167 }, 179 },
168 "dir" => { 180 "dir" => {
169 directory = Some(String::from(arg_split[1])); 181 if arg_split.len() == 2 {
182 directory = Some(String::from(arg_split[1]));
183 } else {
184 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a directory"));
185 }
170 }, 186 },
171 "export" => { 187 "export" => {
172 command = Some(Cmd::Io); 188 command = Some(Cmd::Io);
@@ -212,18 +228,16 @@ pub async fn get_input(config: Cfg, args: Vec<String>) -> MLE<Input> {
212 228
213 match input.clone().command.unwrap() { 229 match input.clone().command.unwrap() {
214 Cmd::Mod => check_mod(input, config), 230 Cmd::Mod => check_mod(input, config),
215 Cmd::List => check_list(input, config), 231 Cmd::List => check_list(input, config).await,
216 _ => Ok(input), 232 _ => Ok(input),
217 } 233 }
218} 234}
219 235
220//Move checks to commands? translate to variables there?
221fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> { 236fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> {
222 if input.mod_options.is_none() { 237 if input.mod_options.is_none() {
223 return Err(MLError::new(ErrorType::ArgumentError, "No mod option")); 238 return Err(MLError::new(ErrorType::ArgumentError, "No mod option"));
224 }; 239 };
225 match input.clone().mod_options.unwrap() { 240 match input.clone().mod_options.unwrap() {
226 //Check for MV if no mod-id on both
227 ModOptions::Add => { 241 ModOptions::Add => {
228 if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No mod id/slug or version id")); }; 242 if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No mod id/slug or version id")); };
229 if input.list_id.is_none() { input.list = Some(get_current_list(config.clone())?); }; 243 if input.list_id.is_none() { input.list = Some(get_current_list(config.clone())?); };
@@ -236,7 +250,7 @@ fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> {
236 } 250 }
237} 251}
238 252
239fn check_list(mut input: Input, config: Cfg) -> MLE<Input> { 253async fn check_list(mut input: Input, config: Cfg) -> MLE<Input> {
240 if input.list_options.is_none() { 254 if input.list_options.is_none() {
241 return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_ARGUMENT")); 255 return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_ARGUMENT"));
242 }; 256 };
@@ -245,11 +259,14 @@ fn check_list(mut input: Input, config: Cfg) -> MLE<Input> {
245 if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no list id specified")); }; 259 if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no list id specified")); };
246 if input.list_mcversion.is_none() { 260 if input.list_mcversion.is_none() {
247 println!("No Minecraft Version specified, defaulting to latest release"); 261 println!("No Minecraft Version specified, defaulting to latest release");
248 //TODO Get latest version 262 input.list_mcversion = Some(get_minecraft_version(config.apis.modrinth, MCVersionType::Release).await);
249 input.list_mcversion = Some(String::from("1.19.3")); 263 };
264 if input.directory.is_none() {
265 let id = input.clone().list_id.unwrap();
266 println!("No download directory specified, defaulting to ./downloads/{}", id);
267 input.directory = Some(format!("./downloads/{}", id))
250 }; 268 };
251 if input.modloader.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no modloader specified")); }; 269 if input.modloader.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no modloader specified")); };
252 if input.directory.is_none() { input.directory = Some(format!("./downloads/{}", input.clone().list_id.expect("earlier if failed"))) };
253 Ok(input) 270 Ok(input)
254 }, 271 },
255 ListOptions::Remove => { 272 ListOptions::Remove => {