From f5e070cdf6628a5ebd981d373929802317104e24 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 09:56:42 +0200 Subject: clippy --fix --- src/apis/modrinth.rs | 10 +++---- src/cache.rs | 2 +- src/commands/download.rs | 2 +- src/commands/io.rs | 8 +++--- src/commands/list.rs | 20 +++++++------- src/commands/modification.rs | 12 ++++----- src/config.rs | 19 ++++++-------- src/db.rs | 62 +++++++++++++++++++++----------------------- src/error.rs | 2 +- src/files.rs | 6 ++--- src/lib.rs | 4 +-- src/main.rs | 6 ++--- 12 files changed, 72 insertions(+), 81 deletions(-) (limited to 'src') diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 9a22633..5366f3d 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs @@ -134,7 +134,7 @@ async fn get( api: &str, path: &str, ) -> Result>, Box> { - let url = format!(r#"{}{}"#, api, path); + let url = format!(r#"{api}{path}"#); let client = Client::builder() .user_agent(format!( @@ -154,7 +154,7 @@ async fn get( } pub async fn project(api: &str, name: &str) -> Project { - let url = format!("project/{}", name); + let url = format!("project/{name}"); let data = get(api, &url).await.unwrap().unwrap(); serde_json::from_slice(&data).unwrap() @@ -162,14 +162,14 @@ pub async fn project(api: &str, name: &str) -> Project { pub async fn projects(api: &str, ids: Vec) -> Vec { let all = ids.join(r#"",""#); - let url = format!(r#"projects?ids=["{}"]"#, all); + let url = format!(r#"projects?ids=["{all}"]"#); let data = get(api, &url).await.unwrap().unwrap(); serde_json::from_slice(&data).unwrap() } -///Get applicable versions from mod_id with list context +///Get applicable versions from `mod_id` with list context pub async fn versions(api: &str, id: String, list: List) -> Vec { let url = format!( r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, @@ -203,7 +203,7 @@ pub fn extract_current_version(versions: Vec) -> MLE { let mut times: Vec<(String, DateTime)> = vec![]; for ver in versions { let stamp = DateTime::parse_from_rfc3339(&ver.date_published)?; - times.push((ver.id, stamp)) + times.push((ver.id, stamp)); } times.sort_by_key(|t| t.1); times.reverse(); diff --git a/src/cache.rs b/src/cache.rs index 8df4d2f..ef096f7 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -8,7 +8,7 @@ use std::{ /// # Panics /// /// Panics if . -pub fn get_cached_versions(path: &str) -> HashMap { +#[must_use] pub fn get_cached_versions(path: &str) -> HashMap { let mut versions: HashMap = HashMap::new(); for file in read_dir(path).unwrap() { let path = file.unwrap().path(); diff --git a/src/commands/download.rs b/src/commands/download.rs index a7cf744..3e50c87 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -71,7 +71,7 @@ pub async fn download( } if clean { - clean_list_dir(¤t_list)? + clean_list_dir(¤t_list)?; }; if !to_download.is_empty() { diff --git a/src/commands/io.rs b/src/commands/io.rs index 8e44b2b..1d17f7c 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -48,13 +48,13 @@ impl ExportList { let mut dl_folder = None; if download { - dl_folder = Some(list.download_folder) + dl_folder = Some(list.download_folder); }; let mods = userlist_get_all_ids(config, list_id)?; let mut versions = vec![]; for m in mods { - versions.push(ExportVersion::from(config, list_id, &m)?) + versions.push(ExportVersion::from(config, list_id, &m)?); } Ok(Self { @@ -80,7 +80,7 @@ pub fn export(config: &Cfg, list: Option) -> MLE<()> { let mut lists: Vec = vec![]; for list_id in list_ids { - progress.set_message(format!("Export {}", list_id)); + progress.set_message(format!("Export {list_id}")); //TODO download option/ new download on import lists.push(ExportList::from(config, &list_id, true)?); } @@ -97,7 +97,7 @@ pub fn export(config: &Cfg, list: Option) -> MLE<()> { progress.set_message("Create file"); let mut file = File::create(&filestr)?; file.write_all(toml.as_bytes())?; - progress.finish_with_message(format!("Exported to {}", filestr)); + progress.finish_with_message(format!("Exported to {filestr}")); Ok(()) } diff --git a/src/commands/list.rs b/src/commands/list.rs index 3665446..63105cf 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -32,32 +32,32 @@ pub fn list_add( ) -> MLE<()> { let p = ProgressBar::new_spinner(); p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); - p.set_message(format!("Create {}", id)); + p.set_message(format!("Create {id}")); lists_insert(config, id, mc_version, modloader, directory)?; - p.finish_with_message(format!("Created {}", id)); + p.finish_with_message(format!("Created {id}")); Ok(()) } pub fn list_change(config: &Cfg, id: &str) -> MLE<()> { let p = ProgressBar::new_spinner(); p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); - p.set_message(format!("Change default list to {}", id)); + p.set_message(format!("Change default list to {id}")); if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { return Err(MLError::new(ErrorType::ArgumentError, "List not found")); }; config_change_current_list(config, id)?; - p.finish_with_message(format!("Changed default list to {}", id)); + p.finish_with_message(format!("Changed default list to {id}")); Ok(()) } pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> { let p = ProgressBar::new_spinner(); p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); - p.set_message(format!("Remove {}", id)); + p.set_message(format!("Remove {id}")); lists_remove(config, id)?; - p.finish_with_message(format!("Removed {}", id)); + p.finish_with_message(format!("Removed {id}")); Ok(()) } @@ -77,15 +77,13 @@ pub async fn list_version( let p = ProgressBar::new_spinner(); p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); p.set_message(format!( - "Change version for list {} to minecraft version: {}", - id, mc_version + "Change version for list {id} to minecraft version: {mc_version}" )); lists_version(config, id, &mc_version)?; p.finish_with_message(format!( - "Changed version for list {} to minecraft version: {}", - id, mc_version + "Changed version for list {id} to minecraft version: {mc_version}" )); let list = lists_get(config, id)?; @@ -96,7 +94,7 @@ pub fn list_list(config: &Cfg) -> MLE<()> { let lists = lists_get_all_ids(config)?; for list in lists { let l = lists_get(config, &list)?; - println!("{}: | {} | {}", l.id, l.mc_version, l.modloader) + println!("{}: | {} | {}", l.id, l.mc_version, l.modloader); } Ok(()) } diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 4488b70..e0e54b2 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -65,7 +65,7 @@ pub async fn mod_add( add_p.inc(1); match m.id { IDSelector::ModificationID(pid) => { - mod_ids.push((pid, m.set_version)) + mod_ids.push((pid, m.set_version)); } IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), } @@ -153,7 +153,7 @@ pub async fn mod_add( }?; if project.current_version.is_some() { - downloadstack.push(project.current_version.unwrap()) + downloadstack.push(project.current_version.unwrap()); }; project_p.inc(1); @@ -245,7 +245,7 @@ async fn get_mod_infos( applicable_versions: available_versions_vec, download_link: file, set_version: *setmap.get(&project.slug).unwrap(), - }) + }); } else { current_version = None; file = String::from("NONE"); @@ -258,7 +258,7 @@ async fn get_mod_infos( applicable_versions: available_versions_vec, download_link: file, set_version: *setmap.get(&project.id).unwrap(), - }) + }); } } @@ -308,7 +308,7 @@ async fn get_ver_info( applicable_versions: vec![String::from(&version.id)], download_link: file, set_version: *setmap.get(&version.id).unwrap(), - }) + }); } Ok(projectinfo) } @@ -335,7 +335,7 @@ pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { progress.set_message("Delete file"); match delete_version(list, version) { - Ok(_) => (), + Ok(()) => (), Err(err) => { if err.to_string() != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" diff --git a/src/config.rs b/src/config.rs index f0eb8f7..3538a69 100644 --- a/src/config.rs +++ b/src/config.rs @@ -70,12 +70,9 @@ impl Cfg { }; //Check versions let versionfile = format!("{}/versions.json", config.versions); - match File::open(&versionfile) { - Ok(..) => (), - Err(..) => { - create_versions_dummy(&versionfile).await?; - check_game_versions(&versionfile, true).await?; - } + if let Ok(..) = File::open(&versionfile) { } else { + create_versions_dummy(&versionfile).await?; + check_game_versions(&versionfile, true).await?; } Ok(config) @@ -94,7 +91,7 @@ fn create_config(path: &str) -> MLE<()> { .to_string(); let default_cfg = Cfg { data: cache_dir.clone(), - cache: format!("{}/cache", cache_dir), + cache: format!("{cache_dir}/cache"), versions: cache_dir, defaults: Defaults { modloader: Modloader::Fabric, @@ -107,7 +104,7 @@ fn create_config(path: &str) -> MLE<()> { create_dir_all(path.split("config.toml").collect::>()[0])?; let mut file = File::create(path)?; file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; - p.finish_with_message(format!("Created default config ({})", path)); + p.finish_with_message(format!("Created default config ({path})")); Ok(()) } @@ -118,7 +115,7 @@ fn create_database(path: &str) -> MLE<()> { File::create(path)?; db_setup(path)?; - p.finish_with_message(format!("Created database ({})", path)); + p.finish_with_message(format!("Created database ({path})")); Ok(()) } @@ -128,7 +125,7 @@ fn create_cache(path: &str) -> MLE<()> { p.set_message("Create cache"); create_dir_all(path)?; - p.finish_with_message(format!("Created cache ({})", path)); + p.finish_with_message(format!("Created cache ({path})")); Ok(()) } @@ -137,6 +134,6 @@ async fn create_versions_dummy(path: &str) -> MLE<()> { p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); p.set_message("Create version file"); File::create(path)?; - p.finish_with_message(format!("Created version file ({})", path)); + p.finish_with_message(format!("Created version file ({path})")); Ok(()) } diff --git a/src/db.rs b/src/db.rs index 49db2fd..6a3c9af 100644 --- a/src/db.rs +++ b/src/db.rs @@ -52,7 +52,7 @@ pub fn mods_get_all_ids( /// ///Will return `MLError` when no mod id is found pub fn mods_get_id(data: &str, slug: &str) -> MLE { - let data = format!("{}/data.db", data); + let data = format!("{data}/data.db"); let connection = Connection::open(data)?; let mut mod_id = String::new(); @@ -157,14 +157,14 @@ pub fn mods_get_versions( for (i, id) in mods.iter().enumerate() { let mut or = " OR"; if i == mods.len() - 1 { - or = "" + or = ""; }; - wherestr = format!("{} id = '{}'{}", wherestr, id, or); + wherestr = format!("{wherestr} id = '{id}'{or}"); } let mut versionmaps: Vec = Vec::new(); let mut stmt = connection.prepare( - format!("SELECT id, versions, title FROM mods {}", wherestr).as_str(), + format!("SELECT id, versions, title FROM mods {wherestr}").as_str(), )?; let id_iter = stmt.query_map([], |row| { Ok(vec![ @@ -179,7 +179,7 @@ pub fn mods_get_versions( versionmaps.push(DBModlistVersions { mod_id: String::from(&version[0]), versions: String::from(&version[1]), - }) + }); } match versionmaps.is_empty() { @@ -208,8 +208,7 @@ pub fn userlist_insert( connection.execute( format!( - "INSERT INTO {} VALUES (?1, ?2, ?3, ?4, 'NONE', ?5)", - list_id + "INSERT INTO {list_id} VALUES (?1, ?2, ?3, ?4, 'NONE', ?5)" ) .as_str(), [ @@ -230,17 +229,17 @@ pub fn userlist_get_all_ids(config: &Cfg, list_id: &str) -> MLE> { let mut mod_ids: Vec = Vec::new(); let mut stmt = connection - .prepare(format!("SELECT mod_id FROM {}", list_id).as_str())?; + .prepare(format!("SELECT mod_id FROM {list_id}").as_str())?; let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { - mod_ids.push(id?) + mod_ids.push(id?); } match mod_ids.is_empty() { true => Err(MLError::new( ErrorType::DBError, - &format!("NO_MODS_USERLIST{}", list_id), + &format!("NO_MODS_USERLIST{list_id}"), )), false => Ok(mod_ids), } @@ -251,7 +250,7 @@ pub fn userlist_remove(config: &Cfg, list_id: &str, mod_id: &str) -> MLE<()> { let connection = Connection::open(data)?; connection.execute( - format!("DELETE FROM {} WHERE mod_id = ?", list_id).as_str(), + format!("DELETE FROM {list_id} WHERE mod_id = ?").as_str(), [mod_id], )?; Ok(()) @@ -268,8 +267,7 @@ pub fn userlist_get_applicable_versions( let mut version: String = String::new(); let mut stmt = connection.prepare( format!( - "SELECT applicable_versions FROM {} WHERE mod_id = ?", - list_id + "SELECT applicable_versions FROM {list_id} WHERE mod_id = ?" ) .as_str(), )?; @@ -295,7 +293,7 @@ pub fn userlist_get_all_applicable_versions_with_mods( let mut versions: Vec<(String, String)> = Vec::new(); let mut stmt = connection.prepare( - format!("SELECT mod_id, applicable_versions FROM {}", list_id).as_str(), + format!("SELECT mod_id, applicable_versions FROM {list_id}").as_str(), )?; let id_iter = stmt.query_map([], |row| { Ok(vec![ @@ -306,7 +304,7 @@ pub fn userlist_get_all_applicable_versions_with_mods( for ver in id_iter { let out = ver?; - versions.push((out[0].to_owned(), out[1].to_owned())); + versions.push((out[0].clone(), out[1].clone())); } if versions.is_empty() { @@ -326,7 +324,7 @@ pub fn userlist_get_current_version( let mut version: String = String::new(); let mut stmt = connection.prepare( - format!("SELECT current_version FROM {} WHERE mod_id = ?", list_id) + format!("SELECT current_version FROM {list_id} WHERE mod_id = ?") .as_str(), )?; let ver_iter = @@ -351,7 +349,7 @@ pub fn userlist_get_all_current_version_ids( let mut versions: Vec = Vec::new(); let mut stmt = connection - .prepare(format!("SELECT current_version FROM {}", list_id).as_str())?; + .prepare(format!("SELECT current_version FROM {list_id}").as_str())?; let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { @@ -374,7 +372,7 @@ pub fn userlist_get_all_current_versions_with_mods( let mut versions: Vec<(String, String)> = Vec::new(); let mut stmt = connection.prepare( - format!("SELECT mod_id, current_version FROM {}", list_id).as_str(), + format!("SELECT mod_id, current_version FROM {list_id}").as_str(), )?; let id_iter = stmt.query_map([], |row| { Ok(vec![ @@ -385,7 +383,7 @@ pub fn userlist_get_all_current_versions_with_mods( for ver in id_iter { let out = ver?; - versions.push((out[0].to_owned(), out[1].to_owned())); + versions.push((out[0].clone(), out[1].clone())); } if versions.is_empty() { @@ -408,7 +406,7 @@ pub fn userlist_get_set_version( let mut set_version: bool = false; let mut stmt = connection.prepare( - format!("SELECT set_version FROM {} WHERE mod_id = ?", list_id) + format!("SELECT set_version FROM {list_id} WHERE mod_id = ?") .as_str(), )?; let ver_iter = @@ -432,7 +430,7 @@ pub fn userlist_change_versions( let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; - connection.execute(format!("UPDATE {} SET current_version = ?1, applicable_versions = ?2, current_download = ?3 WHERE mod_id = ?4", list_id).as_str(), [current_version, versions, link, mod_id])?; + connection.execute(format!("UPDATE {list_id} SET current_version = ?1, applicable_versions = ?2, current_download = ?3 WHERE mod_id = ?4").as_str(), [current_version, versions, link, mod_id])?; Ok(()) } @@ -453,14 +451,13 @@ pub fn userlist_add_disabled_versions( let disabled_versions = match currently_disabled_versions == "NONE" { true => disabled_version, false => { - format!("{}|{}", currently_disabled_versions, disabled_version) + format!("{currently_disabled_versions}|{disabled_version}") } }; connection.execute( format!( - "UPDATE {} SET disabled_versions = ?1 WHERE mod_id = ?2", - list_id + "UPDATE {list_id} SET disabled_versions = ?1 WHERE mod_id = ?2" ) .as_str(), [disabled_versions, mod_id], @@ -478,7 +475,7 @@ pub fn userlist_get_disabled_versions( let mut version: String = String::new(); let mut stmt = connection.prepare( - format!("SELECT disabled_versions FROM {} WHERE mod_id = ?", list_id) + format!("SELECT disabled_versions FROM {list_id} WHERE mod_id = ?") .as_str(), )?; let ver_iter = @@ -503,13 +500,13 @@ pub fn userlist_get_all_downloads( let mut links: Vec = Vec::new(); let mut stmt = connection.prepare( - format!("SELECT current_download FROM {}", list_id).as_str(), + format!("SELECT current_download FROM {list_id}").as_str(), )?; let link_iter = stmt.query_map([], |row| row.get::(0))?; for link in link_iter { let l = link?; - links.push(l) + links.push(l); } if links.is_empty() { @@ -538,7 +535,7 @@ pub fn lists_insert( "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", [id, mc_version, &mod_loader.to_string(), download_folder], )?; - connection.execute(format!("CREATE TABLE {}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT, 'disabled_versions' TEXT DEFAULT 'NONE', 'set_version' INTEGER, CONSTRAINT {}_PK PRIMARY KEY (mod_id) )", id, id).as_str(), [])?; + connection.execute(format!("CREATE TABLE {id}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT, 'disabled_versions' TEXT DEFAULT 'NONE', 'set_version' INTEGER, CONSTRAINT {id}_PK PRIMARY KEY (mod_id) )").as_str(), [])?; Ok(()) } @@ -548,7 +545,7 @@ pub fn lists_remove(config: &Cfg, id: &str) -> MLE<()> { let connection = Connection::open(data)?; connection.execute("DELETE FROM lists WHERE id = ?", [&id])?; - connection.execute(format!("DROP TABLE {}", id).as_str(), [])?; + connection.execute(format!("DROP TABLE {id}").as_str(), [])?; Ok(()) } @@ -611,7 +608,7 @@ pub fn lists_get_all_ids(config: &Cfg) -> MLE> { let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { - list_ids.push(id?) + list_ids.push(id?); } match list_ids.is_empty() { @@ -664,8 +661,7 @@ pub fn s_userlist_update_download( connection.execute( format!( - "UPDATE {} SET current_download = ?1 WHERE mod_id = ?2", - list_id + "UPDATE {list_id} SET current_download = ?1 WHERE mod_id = ?2" ) .as_str(), [link, mod_id], @@ -734,7 +730,7 @@ pub fn s_insert_column( let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; - let mut sql = format!("ALTER TABLE {} ADD '{}' {}", table, column, c_type); + let mut sql = format!("ALTER TABLE {table} ADD '{column}' {c_type}"); if default.is_some() { sql = format!("{} DEFAULT {}", sql, default.unwrap()); diff --git a/src/error.rs b/src/error.rs index a2b37a8..b4cc444 100644 --- a/src/error.rs +++ b/src/error.rs @@ -118,7 +118,7 @@ impl From for MLError { } impl MLError { - pub fn new(etype: ErrorType, message: &str) -> Self { + #[must_use] pub fn new(etype: ErrorType, message: &str) -> Self { Self { etype, message: String::from(message), diff --git a/src/files.rs b/src/files.rs index 3a16c62..bf5a0a0 100644 --- a/src/files.rs +++ b/src/files.rs @@ -55,7 +55,7 @@ pub async fn download_versions( } while js.join_next().await.is_some() { - all.inc(1) + all.inc(1); } all.finish_with_message(format!("âś“Downloading {}", list.id)); @@ -128,7 +128,7 @@ async fn download_file( name: &str, progress: &ProgressBar, ) -> MLE<()> { - let dl_path_file = format!("{}/{}", path, name); + let dl_path_file = format!("{path}/{name}"); let res = Client::new().get(url).send().await?; let size = res.content_length().expect("Couldn't get content length"); @@ -169,7 +169,7 @@ pub fn disable_version( mod_id: String, ) -> MLE<()> { let file = get_file_path(¤t_list, String::from(&versionid))?; - let disabled = format!("{}.disabled", file); + let disabled = format!("{file}.disabled"); rename(file, disabled)?; diff --git a/src/lib.rs b/src/lib.rs index f77befc..c51381c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,7 +103,7 @@ pub fn load_game_versions(path: &str) -> MLE> { } impl VersionLevel { - pub fn from(str: &str) -> Self { + #[must_use] pub fn from(str: &str) -> Self { match str { "release" => VersionLevel::Release, "snapshot" => VersionLevel::Snapshot, @@ -116,7 +116,7 @@ impl VersionLevel { versions_path: &str, force_update: bool, ) -> MLE { - let path = format!("{}/versions.json", versions_path); + let path = format!("{versions_path}/versions.json"); check_game_versions(&path, force_update).await?; let mut versions = load_game_versions(&path)?.into_iter(); diff --git a/src/main.rs b/src/main.rs index 5d60a17..21f2a30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ enum Commands { #[command(subcommand)] command: ListCommands, - /// Force GameVersion update + /// Force `GameVersion` update #[arg(long)] force_gameupdate: bool, }, @@ -262,7 +262,7 @@ async fn main() { Some(l) => lists_get(&config, &l).unwrap(), None => get_current_list(&config).unwrap(), }; - liststack.push(current) + liststack.push(current); } update(&config, liststack, clean, download, remove).await @@ -284,7 +284,7 @@ async fn main() { Some(l) => lists_get(&config, &l).unwrap(), None => get_current_list(&config).unwrap(), }; - liststack.push(current) + liststack.push(current); } download(&config, liststack, clean, remove).await -- cgit v1.2.3