summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs184
1 files changed, 98 insertions, 86 deletions
diff --git a/src/main.rs b/src/main.rs
index a478ec7..f388a82 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,12 +1,12 @@
1#![allow(clippy::too_many_lines)]
2
3use clap::{Parser, Subcommand}; 1use clap::{Parser, Subcommand};
4use modlist::{ 2use modlist::{
5 config::Cfg, 3 config::Cfg,
6 db::{config_get_current_list, lists_get, lists_get_all_ids}, 4 db::{config_get_current_list, lists_get, lists_get_all_ids},
7 download, export, get_current_list, import, list_add, list_change, 5 download,
8 list_lists, list_remove, list_version, mod_add, mod_remove, update, AddMod, 6 error::MLE,
9 IDSelector, List, Modloader, VersionLevel, 7 export, get_current_list, import, list_add, list_change, list_lists,
8 list_remove, list_version, mod_add, mod_remove, update, AddMod, IDSelector,
9 List, Modloader, VersionLevel,
10}; 10};
11 11
12#[derive(Parser)] 12#[derive(Parser)]
@@ -163,90 +163,11 @@ async fn main() {
163 let config = Cfg::init(cli.config).await.unwrap(); 163 let config = Cfg::init(cli.config).await.unwrap();
164 164
165 match cli.command { 165 match cli.command {
166 Commands::Mod { command } => match command { 166 Commands::Mod { command } => handle_mod(config, command).await,
167 ModCommands::Add {
168 id,
169 version,
170 list,
171 download,
172 lock,
173 } => {
174 let listf = match list {
175 Some(list) => lists_get(&config, &list).unwrap(),
176 None => lists_get(
177 &config,
178 &config_get_current_list(&config).unwrap(),
179 )
180 .unwrap(),
181 };
182
183 let marked_id = if version {
184 IDSelector::VersionID(id)
185 } else {
186 IDSelector::ModificationID(id)
187 };
188
189 let add_id = AddMod {
190 id: marked_id,
191 set_version: lock,
192 };
193
194 mod_add(&config, vec![add_id], listf, download).await
195 }
196 ModCommands::Remove { id, list } => {
197 let listf = match list {
198 Some(list) => lists_get(&config, &list).unwrap(),
199 None => lists_get(
200 &config,
201 &config_get_current_list(&config).unwrap(),
202 )
203 .unwrap(),
204 };
205 mod_remove(&config, &id, &listf)
206 }
207 },
208 Commands::List { 167 Commands::List {
209 command, 168 command,
210 force_gameupdate, 169 force_gameupdate,
211 } => match command { 170 } => handle_list(config, command, force_gameupdate).await,
212 ListCommands::Add {
213 id,
214 directory,
215 modloader,
216 version,
217 } => {
218 let ml = match modloader {
219 Some(ml) => Modloader::from(&ml).unwrap(),
220 None => config.defaults.modloader.clone(),
221 };
222
223 let versions_path = &config.versions;
224 let ver = match version {
225 Some(ver) => VersionLevel::from(&ver)
226 .get(versions_path, force_gameupdate)
227 .await
228 .unwrap(),
229 None => config
230 .defaults
231 .version
232 .clone()
233 .get(versions_path, force_gameupdate)
234 .await
235 .unwrap(),
236 };
237
238 list_add(&config, &id, &ver, &ml, &directory)
239 }
240 ListCommands::Remove { id } => list_remove(&config, &id),
241 ListCommands::List => list_lists(&config),
242 ListCommands::Change { id } => list_change(&config, &id),
243 ListCommands::Version {
244 id,
245 version,
246 download,
247 remove,
248 } => list_version(&config, &id, version, download, remove).await,
249 },
250 Commands::Update { 171 Commands::Update {
251 all, 172 all,
252 download, 173 download,
@@ -310,3 +231,94 @@ async fn main() {
310 } 231 }
311 .unwrap(); 232 .unwrap();
312} 233}
234
235async fn handle_mod(config: Cfg, command: ModCommands) -> MLE<()> {
236 match command {
237 ModCommands::Add {
238 id,
239 version,
240 list,
241 download,
242 lock,
243 } => {
244 let listf = match list {
245 Some(list) => lists_get(&config, &list).unwrap(),
246 None => lists_get(
247 &config,
248 &config_get_current_list(&config).unwrap(),
249 )
250 .unwrap(),
251 };
252
253 let marked_id = if version {
254 IDSelector::VersionID(id)
255 } else {
256 IDSelector::ModificationID(id)
257 };
258
259 let add_id = AddMod {
260 id: marked_id,
261 set_version: lock,
262 };
263
264 mod_add(&config, vec![add_id], listf, download).await
265 }
266 ModCommands::Remove { id, list } => {
267 let listf = match list {
268 Some(list) => lists_get(&config, &list).unwrap(),
269 None => lists_get(
270 &config,
271 &config_get_current_list(&config).unwrap(),
272 )
273 .unwrap(),
274 };
275 mod_remove(&config, &id, &listf)
276 }
277 }
278}
279
280async fn handle_list(
281 config: Cfg,
282 command: ListCommands,
283 force_gameupdate: bool,
284) -> MLE<()> {
285 match command {
286 ListCommands::Add {
287 id,
288 directory,
289 modloader,
290 version,
291 } => {
292 let ml = match modloader {
293 Some(ml) => Modloader::from(&ml).unwrap(),
294 None => config.defaults.modloader.clone(),
295 };
296
297 let versions_path = &config.versions;
298 let ver = match version {
299 Some(ver) => VersionLevel::from(&ver)
300 .get(versions_path, force_gameupdate)
301 .await
302 .unwrap(),
303 None => config
304 .defaults
305 .version
306 .clone()
307 .get(versions_path, force_gameupdate)
308 .await
309 .unwrap(),
310 };
311
312 list_add(&config, &id, &ver, &ml, &directory)
313 }
314 ListCommands::Remove { id } => list_remove(&config, &id),
315 ListCommands::List => list_lists(&config),
316 ListCommands::Change { id } => list_change(&config, &id),
317 ListCommands::Version {
318 id,
319 version,
320 download,
321 remove,
322 } => list_version(&config, &id, version, download, remove).await,
323 }
324}