From 942558c75200aaad0b4d8561a1f6999f88f843a4 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 12:31:02 +0200 Subject: remove allow too_many_lines and fix them --- src/main.rs | 184 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 98 insertions(+), 86 deletions(-) (limited to 'src/main.rs') 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 @@ -#![allow(clippy::too_many_lines)] - use clap::{Parser, Subcommand}; use modlist::{ config::Cfg, db::{config_get_current_list, lists_get, lists_get_all_ids}, - download, export, get_current_list, import, list_add, list_change, - list_lists, list_remove, list_version, mod_add, mod_remove, update, AddMod, - IDSelector, List, Modloader, VersionLevel, + download, + error::MLE, + export, get_current_list, import, list_add, list_change, list_lists, + list_remove, list_version, mod_add, mod_remove, update, AddMod, IDSelector, + List, Modloader, VersionLevel, }; #[derive(Parser)] @@ -163,90 +163,11 @@ async fn main() { let config = Cfg::init(cli.config).await.unwrap(); match cli.command { - Commands::Mod { command } => match command { - ModCommands::Add { - id, - version, - list, - download, - lock, - } => { - let listf = match list { - Some(list) => lists_get(&config, &list).unwrap(), - None => lists_get( - &config, - &config_get_current_list(&config).unwrap(), - ) - .unwrap(), - }; - - let marked_id = if version { - IDSelector::VersionID(id) - } else { - IDSelector::ModificationID(id) - }; - - let add_id = AddMod { - id: marked_id, - set_version: lock, - }; - - mod_add(&config, vec![add_id], listf, download).await - } - ModCommands::Remove { id, list } => { - let listf = match list { - Some(list) => lists_get(&config, &list).unwrap(), - None => lists_get( - &config, - &config_get_current_list(&config).unwrap(), - ) - .unwrap(), - }; - mod_remove(&config, &id, &listf) - } - }, + Commands::Mod { command } => handle_mod(config, command).await, Commands::List { command, force_gameupdate, - } => match command { - ListCommands::Add { - id, - directory, - modloader, - version, - } => { - let ml = match modloader { - Some(ml) => Modloader::from(&ml).unwrap(), - None => config.defaults.modloader.clone(), - }; - - let versions_path = &config.versions; - let ver = match version { - Some(ver) => VersionLevel::from(&ver) - .get(versions_path, force_gameupdate) - .await - .unwrap(), - None => config - .defaults - .version - .clone() - .get(versions_path, force_gameupdate) - .await - .unwrap(), - }; - - list_add(&config, &id, &ver, &ml, &directory) - } - ListCommands::Remove { id } => list_remove(&config, &id), - ListCommands::List => list_lists(&config), - ListCommands::Change { id } => list_change(&config, &id), - ListCommands::Version { - id, - version, - download, - remove, - } => list_version(&config, &id, version, download, remove).await, - }, + } => handle_list(config, command, force_gameupdate).await, Commands::Update { all, download, @@ -310,3 +231,94 @@ async fn main() { } .unwrap(); } + +async fn handle_mod(config: Cfg, command: ModCommands) -> MLE<()> { + match command { + ModCommands::Add { + id, + version, + list, + download, + lock, + } => { + let listf = match list { + Some(list) => lists_get(&config, &list).unwrap(), + None => lists_get( + &config, + &config_get_current_list(&config).unwrap(), + ) + .unwrap(), + }; + + let marked_id = if version { + IDSelector::VersionID(id) + } else { + IDSelector::ModificationID(id) + }; + + let add_id = AddMod { + id: marked_id, + set_version: lock, + }; + + mod_add(&config, vec![add_id], listf, download).await + } + ModCommands::Remove { id, list } => { + let listf = match list { + Some(list) => lists_get(&config, &list).unwrap(), + None => lists_get( + &config, + &config_get_current_list(&config).unwrap(), + ) + .unwrap(), + }; + mod_remove(&config, &id, &listf) + } + } +} + +async fn handle_list( + config: Cfg, + command: ListCommands, + force_gameupdate: bool, +) -> MLE<()> { + match command { + ListCommands::Add { + id, + directory, + modloader, + version, + } => { + let ml = match modloader { + Some(ml) => Modloader::from(&ml).unwrap(), + None => config.defaults.modloader.clone(), + }; + + let versions_path = &config.versions; + let ver = match version { + Some(ver) => VersionLevel::from(&ver) + .get(versions_path, force_gameupdate) + .await + .unwrap(), + None => config + .defaults + .version + .clone() + .get(versions_path, force_gameupdate) + .await + .unwrap(), + }; + + list_add(&config, &id, &ver, &ml, &directory) + } + ListCommands::Remove { id } => list_remove(&config, &id), + ListCommands::List => list_lists(&config), + ListCommands::Change { id } => list_change(&config, &id), + ListCommands::Version { + id, + version, + download, + remove, + } => list_version(&config, &id, version, download, remove).await, + } +} -- cgit v1.2.3