From ee98c32616d03df6db5fdca0f74952bc81732362 Mon Sep 17 00:00:00 2001 From: Jade Date: Wed, 8 Nov 2023 03:04:40 -0600 Subject: [PATCH] Make clippy happy --- src/github.rs | 73 +++++++++++------------ src/main.rs | 48 ++++++--------- src/models/modrinth/mod.rs | 28 ++++----- src/models/modrinth/project.rs | 24 ++++---- src/models/modrinth/version.rs | 23 +++---- src/models/project_type/mc_mod/version.rs | 8 --- src/modrinth.rs | 26 ++++---- src/pack.rs | 5 +- src/version.rs | 8 +-- 9 files changed, 106 insertions(+), 137 deletions(-) diff --git a/src/github.rs b/src/github.rs index b0d2e79..f3cca41 100644 --- a/src/github.rs +++ b/src/github.rs @@ -62,7 +62,7 @@ pub async fn create_modpack_release( pack_file: &PackFile, output_file_info: &OutputFileInfo, version_info: &VersionInfo, - changelog: &String, + changelog: &str, ) -> Result<(), anyhow::Error> { println!("Creating GitHub release..."); @@ -74,7 +74,7 @@ pub async fn create_modpack_release( let new_release_req_body = CreateReleaseRequest { tag_name: pack_file.version.clone(), name: Some(version_info.version_name.clone()), - body: Some(changelog.clone()), + body: Some(changelog.to_owned()), }; let new_release_response = @@ -116,7 +116,7 @@ pub async fn create_mod_release( config: &ModConfig, mod_info: &ModInfo, mod_jars: &ModJars, - changelog: &String, + changelog: &str, version_name: &String, ) -> Result<(), anyhow::Error> { println!("Creating GitHub release..."); @@ -129,7 +129,7 @@ pub async fn create_mod_release( let new_release_req_body = CreateReleaseRequest { tag_name: mod_info.version.clone(), name: Some(version_name.into()), - body: Some(changelog.clone()), + body: Some(changelog.to_owned()), }; let new_release_response = @@ -207,45 +207,42 @@ pub async fn upload_mod_jars( } // Upload sources jar - match sources_jar_contents { - Some(file_contents) => { - println!( - "Uploading sources jar as GitHub Release asset `{}`...", - &mod_jars.sources_jar.clone().unwrap().file_name - ); + if let Some(file_contents) = sources_jar_contents { + println!( + "Uploading sources jar as GitHub Release asset `{}`...", + &mod_jars.sources_jar.clone().unwrap().file_name + ); - match reqwest::Client::new() - .post(format!( - "https://uploads.github.com/repos/{}/{}/releases/{}/assets?name=\"{}\"", - github_config.repo_owner, - github_config.repo_name, - release_id, + match reqwest::Client::new() + .post(format!( + "https://uploads.github.com/repos/{}/{}/releases/{}/assets?name=\"{}\"", + github_config.repo_owner, + github_config.repo_name, + release_id, + &mod_jars.sources_jar.clone().unwrap().file_name + )) + .header("User-Agent", env!("CARGO_PKG_NAME")) + .header("Accept", "application/vnd.github+json") + .header("Content-Type", "application/java-archive") + .bearer_auth(&token) + .body(file_contents) + .send() + .await + { + Ok(_) => { + println!( + "Successfully uploaded GitHub Release asset `{}`!", &mod_jars.sources_jar.clone().unwrap().file_name + ) + } + Err(err) => { + return Err(anyhow!( + "Failed to upload GitHub release asset `{}`: {}", + &mod_jars.sources_jar.clone().unwrap().file_name, + err )) - .header("User-Agent", env!("CARGO_PKG_NAME")) - .header("Accept", "application/vnd.github+json") - .header("Content-Type", "application/java-archive") - .bearer_auth(&token) - .body(file_contents) - .send() - .await - { - Ok(_) => { - println!( - "Successfully uploaded GitHub Release asset `{}`!", - &mod_jars.sources_jar.clone().unwrap().file_name - ) - } - Err(err) => { - return Err(anyhow!( - "Failed to upload GitHub release asset `{}`: {}", - &mod_jars.sources_jar.clone().unwrap().file_name, - err - )) - } } } - None => (), } Ok(()) diff --git a/src/main.rs b/src/main.rs index 342a977..07f6526 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,10 +57,7 @@ enum Commands { #[tokio::main] async fn main() -> Result<(), anyhow::Error> { - match dotenvy::dotenv() { - Ok(_) => (), - Err(_) => (), - }; + let _ = dotenvy::dotenv(); let args = CliArgs::parse(); @@ -96,25 +93,19 @@ async fn main() -> Result<(), anyhow::Error> { Err(err) => return Err(err), }; - match version { - Some(ver) => { - let mut new_file_contents = pack_file.clone(); - new_file_contents.version = ver; - let file_contents_string = match toml::to_string(&new_file_contents) { - Ok(file) => file, - Err(err) => { - return Err(anyhow!("Failed to parse new pack data to toml: {}", err)) - } - }; + if let Some(ver) = version { + let mut new_file_contents = pack_file.clone(); + new_file_contents.version = ver; + let file_contents_string = match toml::to_string(&new_file_contents) { + Ok(file) => file, + Err(err) => { + return Err(anyhow!("Failed to parse new pack data to toml: {}", err)) + } + }; - pack_file = new_file_contents; + pack_file = new_file_contents; - match write_pack_file(&tmp_info.dir_path, file_contents_string) { - Ok(_) => (), - Err(err) => return Err(err), - } - } - None => (), + write_pack_file(&tmp_info.dir_path, file_contents_string)? } match Command::new("packwiz") @@ -220,13 +211,11 @@ async fn main() -> Result<(), anyhow::Error> { Err(err) => return Err(anyhow!("Failed to find Java executable: {}", err)), } - let gradlew_path: &Path; - - if env::consts::OS == "windows" { - gradlew_path = Path::new(".\\gradlew.bat"); + let gradlew_path: &Path = if env::consts::OS == "windows" { + Path::new(".\\gradlew.bat") } else { - gradlew_path = Path::new("./gradlew"); - } + Path::new("./gradlew") + }; if !Path::new(gradlew_path).exists() { return Err(anyhow!( @@ -256,10 +245,7 @@ async fn main() -> Result<(), anyhow::Error> { }; // remove previously-compiled jars, if any - match fs::remove_dir(&tmp_info.dir_path.join("build").join("libs")) { - Ok(_) => (), - Err(_) => (), - } + let _ = fs::remove_dir(&tmp_info.dir_path.join("build").join("libs")); let mut gradle_command = Command::new(gradlew_path); diff --git a/src/models/modrinth/mod.rs b/src/models/modrinth/mod.rs index 410bb1b..bef3ed6 100644 --- a/src/models/modrinth/mod.rs +++ b/src/models/modrinth/mod.rs @@ -36,21 +36,21 @@ impl ModrinthUrl { #[derive(Debug, Serialize, Deserialize, Copy, Clone)] #[serde(rename_all = "lowercase")] pub enum Loader { - QUILT, - FABRIC, - NEOFORGE, - FORGE, - LITELOADER, + Quilt, + Fabric, + Neoforge, + Forge, + Liteloader, } impl Loader { pub fn formatted(&self) -> String { match self { - Self::QUILT => "Quilt", - Self::FABRIC => "Fabric", - Self::NEOFORGE => "NeoForge", - Self::FORGE => "Forge", - Self::LITELOADER => "LiteLoader", + Self::Quilt => "Quilt", + Self::Fabric => "Fabric", + Self::Neoforge => "NeoForge", + Self::Forge => "Forge", + Self::Liteloader => "LiteLoader", } .to_string() } @@ -83,8 +83,8 @@ pub struct GalleryObject { #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "lowercase")] pub enum DependencyType { - REQUIRED, - OPTIONAL, - INCOMPATIBLE, - EMBEDDED, + Required, + Optional, + Incompatible, + Embedded, } diff --git a/src/models/modrinth/project.rs b/src/models/modrinth/project.rs index 8f6ed2e..ce7fcdd 100644 --- a/src/models/modrinth/project.rs +++ b/src/models/modrinth/project.rs @@ -4,23 +4,23 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum ProjectType { - MOD, - PLUGIN, - DATAPACK, - SHADER, - RESOURCEPACK, - MODPACK, + Mod, + Plugin, + Datapack, + Shader, + Resourcepack, + Modpack, } impl ProjectType { pub fn formatted(&self) -> String { match self { - Self::MOD => "Mod", - Self::PLUGIN => "Plugin", - Self::DATAPACK => "Data Pack", - Self::SHADER => "Shader", - Self::RESOURCEPACK => "Resource Pack", - Self::MODPACK => "Modpack", + Self::Mod => "Mod", + Self::Plugin => "Plugin", + Self::Datapack => "Data Pack", + Self::Shader => "Shader", + Self::Resourcepack => "Resource Pack", + Self::Modpack => "Modpack", } .to_string() } diff --git a/src/models/modrinth/version.rs b/src/models/modrinth/version.rs index 179a6f0..f75e87e 100644 --- a/src/models/modrinth/version.rs +++ b/src/models/modrinth/version.rs @@ -31,25 +31,20 @@ pub struct VersionDependency { } #[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] pub enum VersionType { - #[serde(rename = "release")] - RELEASE, - #[serde(rename = "beta")] - BETA, - #[serde(rename = "alpha")] - ALPHA, + Release, + Beta, + Alpha, } #[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] pub enum VersionStatus { - #[serde(rename = "listed")] - LISTED, - #[serde(rename = "archived")] - ARCHIVED, - #[serde(rename = "draft")] - DRAFT, - #[serde(rename = "unlisted")] - UNLISTED, + Listed, + Archived, + Draft, + Unlisted, } impl From for VersionDependency { diff --git a/src/models/project_type/mc_mod/version.rs b/src/models/project_type/mc_mod/version.rs index 8e5b714..716dcf3 100644 --- a/src/models/project_type/mc_mod/version.rs +++ b/src/models/project_type/mc_mod/version.rs @@ -19,14 +19,6 @@ pub struct ModFile { pub contents: Vec, } -impl ModVersionInfo { - pub fn loaders_formatted(&self) -> String { - let loaders: &Vec = &self.loaders.iter().map(|l| l.formatted()).collect(); - - loaders.join("/") - } -} - impl ModVersionInfo { pub fn new( config: &ModConfig, diff --git a/src/modrinth.rs b/src/modrinth.rs index 981a9e3..6e9fb8d 100644 --- a/src/modrinth.rs +++ b/src/modrinth.rs @@ -29,15 +29,15 @@ pub struct JarPart { #[derive(Debug, Copy, Clone)] pub enum FileType { - MOD, - SOURCES, + Mod, + Sources, } impl FileType { pub fn part_name(&self) -> String { match self { - Self::MOD => "mod_jar-y5fpv7cUQ6W!sL", - Self::SOURCES => "sources_jar-y5fpv7cUQ6W!sL", + Self::Mod => "mod_jar", + Self::Sources => "sources_jar", } .to_string() } @@ -62,10 +62,10 @@ pub async fn create_modpack_release( changelog: Some(changelog.to_string()), dependencies: vec![], game_versions: vec![pack_file.versions.minecraft.clone()], - version_type: VersionType::RELEASE, + version_type: VersionType::Release, loaders: vec![version_info.loader], featured: false, - requested_status: VersionStatus::LISTED, + requested_status: VersionStatus::Listed, project_id: modrinth_config.project_id, file_parts: vec!["file".to_string()], primary_file: output_file_info.file_name.clone(), @@ -124,10 +124,10 @@ pub async fn create_mod_release( println!("Uploading to Modrinth..."); - let mut file_part_names = vec![FileType::MOD.part_name()]; + let mut file_part_names = vec![FileType::Mod.part_name()]; if mod_files.sources_file.is_some() { - file_part_names.push(FileType::SOURCES.part_name()) + file_part_names.push(FileType::Sources.part_name()) } let mut dependencies: Vec = vec![]; @@ -144,13 +144,13 @@ pub async fn create_mod_release( changelog: Some(changelog.to_string()), dependencies, game_versions: config.mc_versions.to_owned(), - version_type: VersionType::RELEASE, + version_type: VersionType::Release, loaders: config.loaders.to_owned(), featured: false, - requested_status: VersionStatus::LISTED, + requested_status: VersionStatus::Listed, project_id: modrinth_config.project_id, file_parts: file_part_names, - primary_file: FileType::MOD.part_name(), + primary_file: FileType::Mod.part_name(), }; let form = match create_mod_form(mod_files, &form_data).await { @@ -190,7 +190,7 @@ pub async fn create_mod_form( file_part: Part::bytes(mod_files.mod_file.contents.clone()) .file_name(mod_files.mod_file.clone().name) .mime_str("application/java-archive")?, - file_type: FileType::MOD, + file_type: FileType::Mod, }; let sources_part = match &mod_files.sources_file { @@ -204,7 +204,7 @@ pub async fn create_mod_form( Some(JarPart { file_name: file.name.clone(), file_part: part, - file_type: FileType::SOURCES, + file_type: FileType::Sources, }) } None => None, diff --git a/src/pack.rs b/src/pack.rs index 6a9c411..09b3895 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -37,7 +37,7 @@ pub fn write_pack_file(dir_path: &PathBuf, file_contents: String) -> Result<(), pub fn get_output_file(tmp_dir_info: &TempInfo) -> Result { // This should work, as there shouldn't be any more than one .mrpack file at a given time - let glob_pattern = match glob( + let mut glob_pattern = match glob( match Path::new(&tmp_dir_info.dir_path).join("*.mrpack").to_str() { Some(path) => path, None => return Err(anyhow!("Failed to parse modpack glob to string.")), @@ -48,9 +48,8 @@ pub fn get_output_file(tmp_dir_info: &TempInfo) -> Result match path { diff --git a/src/version.rs b/src/version.rs index f450e4a..d2bde0e 100644 --- a/src/version.rs +++ b/src/version.rs @@ -11,13 +11,13 @@ pub fn get_modpack_version_info( output_info: &OutputFileInfo, ) -> Result { let loader_opt = if pack_file.versions.quilt.is_some() { - Some(QUILT) + Some(Quilt) } else if pack_file.versions.fabric.is_some() { - Some(FABRIC) + Some(Fabric) } else if pack_file.versions.forge.is_some() { - Some(FORGE) + Some(Forge) } else if pack_file.versions.liteloader.is_some() { - Some(LITELOADER) + Some(Liteloader) } else { None };