From 8050cfcd70a16273cc2814fe29c8ee08320d85d3 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 20 Apr 2023 15:13:58 +0200 Subject: cargo fmt --- src/main.rs | 115 ++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 73 insertions(+), 42 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index e845be1..eb5ee0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,10 @@ use clap::{Parser, Subcommand}; -use modlist::{config::Cfg, mod_add, mod_remove, db::{lists_get, config_get_current_list, lists_get_all_ids}, IDSelector, download, update, List, get_current_list, import, devdir, export, list_add, Modloader, list_version, list_remove, list_change}; +use modlist::{ + config::Cfg, + db::{config_get_current_list, lists_get, lists_get_all_ids}, + devdir, download, export, get_current_list, import, list_add, list_change, list_remove, + list_version, mod_add, mod_remove, update, IDSelector, List, Modloader, +}; //TODO make default list optional #[derive(Parser)] @@ -17,13 +22,13 @@ enum Commands { }, List { #[command(subcommand)] - command: ListCommands + command: ListCommands, }, Download { /// download all lists #[arg(short, long)] all: bool, - + /// clean all mods before downloading them #[arg(short, long)] clean: bool, @@ -36,11 +41,11 @@ enum Commands { /// download all lists #[arg(short, long)] all: bool, - + /// directly download updated mods #[arg(short, long)] download: bool, - + /// clean all mods before downloading them #[arg(short, long)] clean: bool, @@ -59,7 +64,7 @@ enum Commands { }, Export { /// the list you want to export - list: Option + list: Option, }, } @@ -68,7 +73,7 @@ enum ModCommands { Add { /// id of the mod/version id: String, - + /// set id mode to version #[arg(short, long)] version: bool, @@ -83,7 +88,7 @@ enum ModCommands { /// optional List selection, else default list will be used #[arg(short, long)] - list: Option + list: Option, }, Remove { /// id, name or title of the mod @@ -91,8 +96,8 @@ enum ModCommands { /// optional List selection, else default list will be used #[arg(short, long)] - list: Option - } + list: Option, + }, } #[derive(Subcommand)] @@ -109,12 +114,12 @@ enum ListCommands { }, Remove { /// id, name or title of the list - id: String + id: String, }, List, Change { /// id of the list to change to - id: String + id: String, }, Version { /// list id @@ -129,12 +134,11 @@ enum ListCommands { /// delete disabled versions #[arg(short, long)] remove: bool, - } + }, } #[tokio::main] async fn main() { - let cli = Cli::parse(); let config = Cfg::init("modlist.toml").unwrap(); @@ -143,13 +147,22 @@ async fn main() { //TODO setup? maybe setup on install match cli.command { Commands::Mod { command } => { - match command { #[allow(unused_variables)] - ModCommands::Add { id, version, list, download, lock } => { + ModCommands::Add { + id, + version, + list, + download, + lock, + } => { let listf = match list { Some(list) => lists_get(config.clone(), list).unwrap(), - None => lists_get(config.clone(), config_get_current_list(config.clone()).unwrap()).unwrap(), + None => lists_get( + config.clone(), + config_get_current_list(config.clone()).unwrap(), + ) + .unwrap(), }; let marked_id = match version { @@ -164,15 +177,24 @@ async fn main() { //TODO add success even if no file found let listf = match list { Some(list) => lists_get(config.clone(), list).unwrap(), - None => lists_get(config.clone(), config_get_current_list(config.clone()).unwrap()).unwrap(), + None => lists_get( + config.clone(), + config_get_current_list(config.clone()).unwrap(), + ) + .unwrap(), }; mod_remove(config, &id, listf) } } - }, + } Commands::List { command } => { match command { - ListCommands::Add { id, directory, modloader, version } => { + ListCommands::Add { + id, + directory, + modloader, + version, + } => { let ml = match modloader { Some(ml) => Modloader::from(&ml).unwrap(), //TODO add default modloader to config @@ -187,23 +209,27 @@ async fn main() { }; list_add(config, id, ver, ml, directory) - }, - ListCommands::Remove { id } => { - list_remove(config, id) - }, + } + ListCommands::Remove { id } => list_remove(config, id), ListCommands::List => { todo!() - }, - ListCommands::Change { id } => { - list_change(config, id) - }, - ListCommands::Version { id, version, download, remove } => { - list_version(config, id, version, download, remove).await } + ListCommands::Change { id } => list_change(config, id), + ListCommands::Version { + id, + version, + download, + remove, + } => list_version(config, id, version, download, remove).await, } - }, + } //TODO a add specific list - Commands::Update { all, download, clean, remove } => { + Commands::Update { + all, + download, + clean, + remove, + } => { let mut liststack: Vec = vec![]; if all { let list_ids = lists_get_all_ids(config.clone()).unwrap(); @@ -216,21 +242,26 @@ async fn main() { liststack.push(current) } update(config, liststack, clean, download, remove).await - }, + } //TODO add specific list - Commands::Download { all, clean, remove } => { - download(config, all, clean, remove).await - }, + Commands::Download { all, clean, remove } => download(config, all, clean, remove).await, Commands::Import { file, download } => { let filestr: String = match file { Some(args) => args, - None => devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str()), + None => devdir( + dirs::home_dir() + .unwrap() + .join("mlexport.toml") + .into_os_string() + .into_string() + .unwrap() + .as_str(), + ), }; import(config, filestr, download).await - }, - Commands::Export { list } => { - export(config, list) - }, - }.unwrap(); + } + Commands::Export { list } => export(config, list), + } + .unwrap(); } -- cgit v1.2.3