summaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/input.rs b/src/input.rs
index be24660..a41f671 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -42,6 +42,7 @@ pub enum ListOptions {
42 Add, 42 Add,
43 Remove, 43 Remove,
44 Change, 44 Change,
45 Version,
45} 46}
46 47
47#[derive(Debug, Clone, PartialEq, Eq)] 48#[derive(Debug, Clone, PartialEq, Eq)]
@@ -119,14 +120,18 @@ impl Input {
119 "clean" => { 120 "clean" => {
120 clean = true; 121 clean = true;
121 }, 122 },
122 "direct-download" => { 123 "no-download" => {
123 direct_download = true; 124 direct_download = false;
124 }, 125 },
125 "delete_old" => { 126 "delete_old" => {
126 delete_old = true; 127 delete_old = true;
127 }, 128 },
128 "l" => { 129 "l" => {
129 list = Some(lists_get(config.clone(), String::from(arg_split[1]))?); 130 if arg_split.len() == 2 {
131 list = Some(lists_get(config.clone(), String::from(arg_split[1]))?);
132 } else {
133 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a list via it's id"));
134 }
130 } 135 }
131 "la" => { 136 "la" => {
132 command = Some(Cmd::List); 137 command = Some(Cmd::List);
@@ -136,18 +141,26 @@ impl Input {
136 "lr" => { 141 "lr" => {
137 command = Some(Cmd::List); 142 command = Some(Cmd::List);
138 list_options = Some(ListOptions::Remove); 143 list_options = Some(ListOptions::Remove);
139 if arg_split.len() == 2 {
140 list_id = Some(String::from(arg_split[1]));
141 list = Some(lists_get(config.clone(), list_id.clone().unwrap())?)
142 }
143 }, 144 },
144 "lc" => { 145 "lc" => {
145 command = Some(Cmd::List); 146 command = Some(Cmd::List);
146 list_options = Some(ListOptions::Change); 147 list_options = Some(ListOptions::Change);
147 list_id = Some(String::from(arg_split[1]));
148 }, 148 },
149 "lv" => { 149 "lv" => {
150 list_mcversion = Some(String::from(arg_split[1])); 150 command = Some(Cmd::List);
151 list_options = Some(ListOptions::Version);
152 if arg_split.len() == 2 {
153 list_mcversion = Some(String::from(arg_split[1]));
154 } else {
155 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a minecraft version"));
156 }
157 },
158 "mcv" => {
159 if arg_split.len() == 2 {
160 list_mcversion = Some(String::from(arg_split[1]));
161 } else {
162 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a minecraft version"));
163 }
151 }, 164 },
152 "ml" => { 165 "ml" => {
153 modloader = Some(Modloader::from(arg_split[1])?); 166 modloader = Some(Modloader::from(arg_split[1])?);
@@ -199,7 +212,7 @@ pub async fn get_input(config: Cfg, args: Vec<String>) -> MLE<Input> {
199 212
200 match input.clone().command.unwrap() { 213 match input.clone().command.unwrap() {
201 Cmd::Mod => check_mod(input, config), 214 Cmd::Mod => check_mod(input, config),
202 Cmd::List => check_list(input), 215 Cmd::List => check_list(input, config),
203 _ => Ok(input), 216 _ => Ok(input),
204 } 217 }
205} 218}
@@ -223,7 +236,7 @@ fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> {
223 } 236 }
224} 237}
225 238
226fn check_list(mut input: Input) -> MLE<Input> { 239fn check_list(mut input: Input, config: Cfg) -> MLE<Input> {
227 if input.list_options.is_none() { 240 if input.list_options.is_none() {
228 return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_ARGUMENT")); 241 return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_ARGUMENT"));
229 }; 242 };
@@ -240,12 +253,19 @@ fn check_list(mut input: Input) -> MLE<Input> {
240 Ok(input) 253 Ok(input)
241 }, 254 },
242 ListOptions::Remove => { 255 ListOptions::Remove => {
243 if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "LISTS_NO_ID")); }; 256 if input.list.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_SPECIFIED")); };
244 Ok(input) 257 Ok(input)
245 }, 258 },
246 ListOptions::Change => { 259 ListOptions::Change => {
247 //TODO check if no change 260 //TODO check if no change
248 if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "LISTS_NO_ID")); }; 261 if input.list.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_SPECIFIED")); };
262 Ok(input)
263 },
264 ListOptions::Version => {
265 if input.list.is_none() {
266 println!("No list specified, using default");
267 input.list = Some(get_current_list(config)?);
268 };
249 Ok(input) 269 Ok(input)
250 } 270 }
251 } 271 }