From 2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Fri, 26 May 2023 17:40:27 +0200 Subject: added full progress? cargo fmt --- src/main.rs | 164 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 85 insertions(+), 79 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index d03f88a..d9ad6af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,8 @@ 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_remove, list_version, - mod_add, mod_remove, update, IDSelector, List, Modloader, VersionLevel, list_list, AddMod, + download, export, get_current_list, import, list_add, list_change, list_list, list_remove, + list_version, mod_add, mod_remove, update, AddMod, IDSelector, List, Modloader, VersionLevel, }; #[derive(Parser)] @@ -43,7 +43,7 @@ enum Commands { /// remove disabled versions #[arg(short, long)] remove: bool, - + /// optional List selection, else default list will be used #[arg(short, long)] list: Option, @@ -81,7 +81,7 @@ enum Commands { /// the list you want to export list: Option, }, - Test + Test, } #[derive(Subcommand)] @@ -160,86 +160,87 @@ 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(), - }; + 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 = match version { - true => IDSelector::VersionID(id), - false => IDSelector::ModificationID(id), - }; + let marked_id = match version { + true => IDSelector::VersionID(id), + false => IDSelector::ModificationID(id), + }; - let add_id = AddMod { id: marked_id, set_version: lock }; + 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) - } + mod_add(&config, vec![add_id], listf, download).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_list(&config) - } - ListCommands::Change { id } => list_change(&config, id), - ListCommands::Version { - id, - version, - download, - remove, - } => list_version(&config, &id, version, download, remove).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::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_list(&config), + ListCommands::Change { id } => list_change(&config, &id), + ListCommands::Version { + id, + version, + download, + remove, + } => list_version(&config, &id, version, download, remove).await, + }, Commands::Update { all, download, clean, remove, - list + list, } => { let mut liststack: Vec = vec![]; if all { @@ -248,7 +249,7 @@ async fn main() { liststack.push(lists_get(&config, &id).unwrap()); } } else { - let current = match list { + let current = match list { Some(l) => lists_get(&config, &l).unwrap(), None => get_current_list(&config).unwrap(), }; @@ -257,7 +258,12 @@ async fn main() { update(&config, liststack, clean, download, remove).await } - Commands::Download { all, clean, remove, list } => { + Commands::Download { + all, + clean, + remove, + list, + } => { let mut liststack: Vec = vec![]; if all { let list_ids = lists_get_all_ids(&config).unwrap(); @@ -265,15 +271,15 @@ async fn main() { liststack.push(lists_get(&config, &id).unwrap()); } } else { - let current = match list { + let current = match list { Some(l) => lists_get(&config, &l).unwrap(), None => get_current_list(&config).unwrap(), }; liststack.push(current) } - download(&config, liststack, clean, remove).await - }, + download(&config, liststack, clean, remove).await + } Commands::Import { file, download } => { let filestr: String = match file { Some(args) => args, -- cgit v1.2.3