From 4e6466af1329f7b9e341df2e76ab696d11f80c93 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Thu, 27 Apr 2023 10:08:20 +0200 Subject: version bump, cargo fmt and cargo update --- src/cache.rs | 5 ++++- src/config.rs | 13 +++++++++---- src/db.rs | 1 - src/files.rs | 19 +++++++++++++------ src/lib.rs | 2 +- src/main.rs | 22 ++++++++++------------ 6 files changed, 37 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/cache.rs b/src/cache.rs index 44029e0..11645d1 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -1,4 +1,7 @@ -use std::{collections::HashMap, fs::{read_dir, copy}}; +use std::{ + collections::HashMap, + fs::{copy, read_dir}, +}; /// . /// diff --git a/src/config.rs b/src/config.rs index 817d22b..61db1c7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,11 +1,12 @@ use std::{ - fs::{File, create_dir_all}, - io::{Read, Write}, path::Path, + fs::{create_dir_all, File}, + io::{Read, Write}, + path::Path, }; use serde::{Deserialize, Serialize}; -use crate::{error::MLE, db::db_setup}; +use crate::{db::db_setup, error::MLE}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Cfg { @@ -23,7 +24,11 @@ impl Cfg { pub fn init(path: Option) -> MLE { let configfile = match path.clone() { Some(p) => String::from(p), - None => dirs::config_dir().unwrap().join("modlist.toml").to_string_lossy().to_string(), + None => dirs::config_dir() + .unwrap() + .join("modlist.toml") + .to_string_lossy() + .to_string(), }; let mut file = match File::open(&configfile) { diff --git a/src/db.rs b/src/db.rs index 36fab75..abfe1dd 100644 --- a/src/db.rs +++ b/src/db.rs @@ -702,7 +702,6 @@ pub fn s_insert_column( } pub fn db_setup(path: &str) -> MLE<()> { - let connection = Connection::open(path)?; connection.execute_batch( diff --git a/src/files.rs b/src/files.rs index a73fc18..59fc7de 100644 --- a/src/files.rs +++ b/src/files.rs @@ -2,20 +2,20 @@ use futures_util::StreamExt; use reqwest::Client; use std::{ collections::HashMap, - fs::{read_dir, remove_file, rename, File, copy}, + fs::{copy, read_dir, remove_file, rename, File}, io::Write, }; use crate::{ + cache::{copy_cached_version, get_cached_versions}, config::Cfg, db::{mods_get_info, userlist_add_disabled_versions}, error::{ErrorType, MLError, MLE}, modrinth::Version, - List, cache::{get_cached_versions, copy_cached_version}, + List, }; pub async fn download_versions(list: List, config: Cfg, versions: Vec) -> MLE { - let mut cached = get_cached_versions(&config.cache); println!("{:#?}", cached); @@ -30,7 +30,10 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec) //Check cache if already downloaded let c = cached.remove(&ver.id); if c.is_some() { - print!("\t└({})Get version {} from cache", project_info.title, ver.id); + print!( + "\t└({})Get version {} from cache", + project_info.title, ver.id + ); //Force flush of stdout, else print! doesn't print instantly std::io::stdout().flush()?; copy_cached_version(&c.unwrap(), &dl_path); @@ -52,7 +55,12 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec) ver.id, extension ); - download_file(primary_file.url, list.clone().download_folder, filename.clone()).await?; + download_file( + primary_file.url, + list.clone().download_folder, + filename.clone(), + ) + .await?; println!(" ✓"); //Copy file to cache print!("\t └Copy to cache"); @@ -64,7 +72,6 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec) copy(dl_path_file, cache_path)?; println!(" ✓"); } - } Ok(dl_path) diff --git a/src/lib.rs b/src/lib.rs index 0bf3076..185edd7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,10 @@ pub mod apis; +pub mod cache; pub mod commands; pub mod config; pub mod db; pub mod error; pub mod files; -pub mod cache; use std::fmt::Display; diff --git a/src/main.rs b/src/main.rs index 30c4001..0ecb850 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, + download, export, get_current_list, import, list_add, list_change, list_remove, list_version, + mod_add, mod_remove, update, IDSelector, List, Modloader, }; //TODO implement remote sql db @@ -14,7 +14,7 @@ use modlist::{ struct Cli { #[command(subcommand)] command: Commands, - + /// config file path #[arg(short, long)] config: Option, @@ -146,7 +146,7 @@ enum ListCommands { #[tokio::main] async fn main() { let cli = Cli::parse(); - + let config = Cfg::init(cli.config).unwrap(); println!("{:?}", config); @@ -253,14 +253,12 @@ async fn main() { Commands::Import { file, download } => { let filestr: String = match file { Some(args) => args, - None => - dirs::home_dir() - .unwrap() - .join("mlexport.toml") - .into_os_string() - .into_string() - .unwrap() - , + None => dirs::home_dir() + .unwrap() + .join("mlexport.toml") + .into_os_string() + .into_string() + .unwrap(), }; import(config, filestr, download).await -- cgit v1.2.3