Skip to content

Commit

Permalink
refactor: let clippy do its job
Browse files Browse the repository at this point in the history
  • Loading branch information
null8626 committed Sep 23, 2024
1 parent 4de24de commit c17c43a
Show file tree
Hide file tree
Showing 43 changed files with 80 additions and 89 deletions.
4 changes: 2 additions & 2 deletions src/api/app/actions/build/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl App {

let x = input_base.clone();
futures::stream::iter(WalkDir::new(*input_base.clone()))
.map(|res| res.with_context({ || format!("Bootstrapping folder: {x:?}") }))
.map(|res| res.with_context(|| format!("Bootstrapping folder: {x:?}")))
.try_for_each_concurrent(Some(MAX_CONCURRENT_TASKS), move |entry| {
let app = self.clone();
let output_base = output_base.clone();
Expand All @@ -75,7 +75,7 @@ impl App {
&output_base,
&input_base,
entry.path(),
&changed_variables,
changed_variables,
)
.await
.with_context(|| format!("Bootstrapping file: {:?}", entry.path()))
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/actions/build/server_jar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ impl App {
if let Some((_, server)) = &*self.server.read().await {
println!("Installing server jar");

let jar = server.get_jar(&self).await?;
let jar = server.get_jar(self).await?;

let steps = jar.resolve_steps(&self, Environment::Server).await?;
let steps = jar.resolve_steps(self, Environment::Server).await?;

self.execute_steps(base, &steps).await?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/actions/lockfile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl App {
Ok(())
}

/// Adds an addon to the new_lockfile
/// Adds an addon to the `new_lockfile`
pub async fn add_addon_to_lockfile(self: Arc<Self>, addon: Addon) {
self.new_lockfile.write().await.addons.push(addon);
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl App {
let mut addons = vec![];

for (relative_to, source) in self.collect_sources().await? {
addons.extend_from_slice(&source.resolve_addons(&self, &relative_to).await?);
addons.extend_from_slice(&source.resolve_addons(self, &relative_to).await?);
}

Ok(addons)
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl App {

let full = res.bytes().await?;

Ok(serde_json::from_slice(&full)
.with_context(|| format!("JSON parsing error: {}", String::from_utf8_lossy(&full)))?)
serde_json::from_slice(&full)
.with_context(|| format!("JSON parsing error: {}", String::from_utf8_lossy(&full)))
}
}
4 changes: 2 additions & 2 deletions src/api/app/step/cache_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl App {
hasher.update(&item);
}

let hash = hex::encode(&hasher.finalize());
let hash = hex::encode(hasher.finalize());

if content == hash {
// size and hash match, skip rest of the steps
Expand Down Expand Up @@ -146,7 +146,7 @@ impl App {
}

if let Some((_, hasher, content)) = hasher {
let hash = hex::encode(&hasher.finalize());
let hash = hex::encode(hasher.finalize());

if hash != content {
// TODO: print warning
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/step/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl App {

let target_destination = cache_destination.as_ref().unwrap_or(&output_destination);

create_parents(&target_destination).await?;
create_parents(target_destination).await?;
let target_file = tokio::fs::File::create(&target_destination)
.await
.with_context(|| format!("Creating file: {}", target_destination.display()))?;
Expand All @@ -55,7 +55,7 @@ impl App {
}

if let Some((_, hasher, content)) = hasher {
let hash = hex::encode(&hasher.finalize());
let hash = hex::encode(hasher.finalize());

if hash != content {
bail!("Mismatched hash!");
Expand Down
7 changes: 3 additions & 4 deletions src/api/app/step/execute_java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ impl App {

let java = tools::java::get_java_installations()
.await
.into_iter()
.iter()
.find(|j| j.version >= version.unwrap_or_default())
.ok_or(anyhow!(
"Java with version {} or higher not found, cannot proceed",
version.map(|v| v.to_string()).unwrap_or("any".to_owned())
version.map_or("any".to_owned(), |v| v.to_string())
))?;

let mut proc = JavaProcess::new(&dir.canonicalize()?, &java.path, args)?;
Expand All @@ -44,8 +44,7 @@ impl App {
bail!(
"Java process exited with code {}",
res.code()
.map(|x| x.to_string())
.unwrap_or("unknown".to_owned())
.map_or("unknown".to_owned(), |x| x.to_string())
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/api/app/step/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ mod remove_file;
use super::App;

impl App {
/// Execute a list of steps, taking care of their StepResult's.
/// Skips the next step when a step returns StepResult::Skip
/// Execute a list of steps, taking care of their `StepResult`'s.
/// Skips the next step when a step returns `StepResult::Skip`
pub async fn execute_steps(&self, dir: &Path, steps: &[Step]) -> Result<()> {
let mut iter = steps.iter();

Expand Down Expand Up @@ -43,7 +43,7 @@ impl App {
.await
.with_context(|| format!("URL: {url}"))
.with_context(|| format!("File: {metadata:?}"))
.with_context(|| format!("Downloading a file")),
.with_context(|| "Downloading a file".to_string()),

Step::ExecuteJava {
args,
Expand Down
3 changes: 1 addition & 2 deletions src/api/models/addon/addon_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ impl AddonTarget {
Self::from_str(
&Path::new(path)
.parent()
.map(|p| p.to_string_lossy().into_owned())
.unwrap_or(".".to_owned()),
.map_or(".".to_owned(), |p| p.to_string_lossy().into_owned()),
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/models/launcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::{borrow::ToOwned, collections::HashMap, env};

use crate::api::utils::serde::*;
use crate::api::utils::serde::is_default;

mod preset_flags;
pub use preset_flags::*;
Expand Down
2 changes: 1 addition & 1 deletion src/api/models/legacy/server_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use crate::api::utils::serde::*;
use crate::api::utils::serde::is_default;

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
Expand Down
2 changes: 1 addition & 1 deletion src/api/models/legacy/server_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::api::utils::serde::*;
use crate::api::utils::serde::str_latest;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use super::LegacyDownloadable;
Expand Down
10 changes: 1 addition & 9 deletions src/api/models/lockfile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,13 @@ use super::Addon;
pub const LOCKFILE: &str = ".mcman.lock";

#[derive(Debug, Serialize, Deserialize)]
#[derive(Default)]
pub struct Lockfile {
pub vars: HashMap<String, String>,
pub addons: Vec<Addon>,
pub bootstrapped_files: HashMap<PathBuf, BootstrappedFile>,
}

impl Default for Lockfile {
fn default() -> Self {
Self {
addons: vec![],
bootstrapped_files: HashMap::new(),
vars: HashMap::new(),
}
}
}

pub enum LockfileMessage {
BootstrapFile(PathBuf, BootstrappedFile),
Expand Down
2 changes: 1 addition & 1 deletion src/api/models/markdown/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::api::utils::serde::*;
use crate::api::utils::serde::{bool_true, is_default, is_true};

pub mod render;

Expand Down
2 changes: 1 addition & 1 deletion src/api/models/modpack_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ impl ModpackSource {
Self::Remote { url } => url,
};

Ok(Accessor::from(str).with_context(|| "Creating Accessor")?)
Accessor::from(str).with_context(|| "Creating Accessor")
}
}
2 changes: 1 addition & 1 deletion src/api/models/mrpack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::{server::ServerJar, Addon, AddonTarget, AddonType};
pub async fn resolve_mrpack_serverjar(app: &App, mut accessor: Accessor) -> Result<ServerJar> {
let index: MRPackIndex = accessor.json(app, MRPACK_INDEX_FILE).await?;

Ok(ServerJar::try_from(index.dependencies.clone())?)
ServerJar::try_from(index.dependencies.clone())
}

pub async fn resolve_mrpack_addons(app: &App, mut accessor: Accessor) -> Result<Vec<Addon>> {
Expand Down
2 changes: 1 addition & 1 deletion src/api/models/packwiz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{server::ServerJar, Addon, AddonTarget};
pub async fn resolve_packwiz_serverjar(app: &App, mut accessor: Accessor) -> Result<ServerJar> {
let pack: PackwizPack = accessor.toml(app, PACK_TOML).await?;

Ok(ServerJar::try_from(pack.versions.clone())?)
ServerJar::try_from(pack.versions.clone())
}

pub async fn resolve_packwiz_addons(app: &App, mut accessor: Accessor) -> Result<Vec<Addon>> {
Expand Down
7 changes: 3 additions & 4 deletions src/api/models/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Default for Server {
}

impl Server {
/// Gets the ServerJar via `jar` OR `Source` where `type=modpack`
/// Gets the `ServerJar` via `jar` OR `Source` where `type=modpack`
pub async fn get_jar(&self, app: &App) -> Result<ServerJar> {
let relative_to = app.server.read().await.as_ref().map(|(p, _)| p.clone());

Expand All @@ -86,8 +86,7 @@ impl Server {
if let Some(v) = self.launcher.java_version {
get_java_installation_for(v)
.await
.map(|j| j.path.to_string_lossy().into_owned())
.unwrap_or(String::from("java"))
.map_or(String::from("java"), |j| j.path.to_string_lossy().into_owned())
} else {
String::from("java")
}
Expand All @@ -96,7 +95,7 @@ impl Server {
pub fn get_execution_arguments(&self) -> Vec<String> {
self.jar
.as_ref()
.map(|s| s.get_execution_arguments())
.map(server_type::ServerJar::get_execution_arguments)
.unwrap_or_default()
}

Expand Down
16 changes: 8 additions & 8 deletions src/api/models/server/server_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::api::{
models::{Addon, AddonTarget, AddonType, Environment},
sources::buildtools,
step::Step,
utils::serde::*,
utils::serde::str_latest,
};
use anyhow::{anyhow, Result};
use schemars::JsonSchema;
Expand Down Expand Up @@ -52,36 +52,36 @@ impl TryFrom<HashMap<String, String>> for ServerJar {
server_type = Some(ServerType::Fabric {
loader: v,
installer: String::from("latest"),
})
});
}

if let Some(v) = value.get("fabric-loader").cloned() {
server_type = Some(ServerType::Fabric {
loader: v,
installer: String::from("latest"),
})
});
}

if let Some(v) = value.get("quilt").cloned() {
server_type = Some(ServerType::Quilt {
loader: v,
installer: String::from("latest"),
})
});
}

if let Some(v) = value.get("quilt-loader").cloned() {
server_type = Some(ServerType::Quilt {
loader: v,
installer: String::from("latest"),
})
});
}

if let Some(v) = value.get("forge").cloned() {
server_type = Some(ServerType::Forge { loader: v })
server_type = Some(ServerType::Forge { loader: v });
}

if let Some(v) = value.get("neoforge").cloned() {
server_type = Some(ServerType::NeoForge { loader: v })
server_type = Some(ServerType::NeoForge { loader: v });
}

Ok(ServerJar {
Expand Down Expand Up @@ -162,7 +162,7 @@ impl ServerJar {
ServerType::BuildTools { .. }
| ServerType::PaperMC { .. }
| ServerType::Purpur { .. } => ServerFlavor::Patched,
ServerType::Custom { flavor, .. } => flavor.clone(),
ServerType::Custom { flavor, .. } => *flavor,
ServerType::Fabric { .. }
| ServerType::Forge { .. }
| ServerType::Quilt { .. }
Expand Down
2 changes: 1 addition & 1 deletion src/api/models/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Source {

pub fn modpack_type(&self) -> Option<ModpackType> {
match &self.source_type {
SourceType::Modpack { modpack_type, .. } => Some(modpack_type.clone()),
SourceType::Modpack { modpack_type, .. } => Some(*modpack_type),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/sources/buildtools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub async fn resolve_buildtools_jar(app: &App) -> Result<(String, FileMeta)> {
.await
}

/// Resolve steps for using BuildTools to compile a server jar
/// Resolve steps for using `BuildTools` to compile a server jar
pub async fn resolve_compile_steps(
_app: &App,
jar_name: &str,
Expand Down
6 changes: 3 additions & 3 deletions src/api/sources/curseforge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ pub fn convert_hashes(hashes: Vec<CurseforgeFileHash>) -> HashMap<HashFormat, St
map
}

impl Into<HashFormat> for CurseforgeHashAlgo {
fn into(self) -> HashFormat {
match self {
impl From<CurseforgeHashAlgo> for HashFormat {
fn from(val: CurseforgeHashAlgo) -> Self {
match val {
CurseforgeHashAlgo::Sha1 => HashFormat::Sha1,
CurseforgeHashAlgo::Md5 => HashFormat::Md5,
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/sources/modrinth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> ModrinthAPI<'a> {
}

pub async fn fetch_versions(&self, id: &str) -> Result<Vec<ModrinthVersion>> {
Ok(self.fetch_all_versions(id).await?)
self.fetch_all_versions(id).await
}

pub async fn fetch_version(&self, id: &str, version: &str) -> Result<ModrinthVersion> {
Expand All @@ -60,7 +60,7 @@ impl<'a> ModrinthAPI<'a> {
let path = "modrinth/ids.json";
let store = self.0.cache.try_get_json::<HashMap<String, String>>(path)?;

if let Some(id) = store.as_ref().map(|ids| ids.get(slug)).flatten() {
if let Some(id) = store.as_ref().and_then(|ids| ids.get(slug)) {
return Ok(id.to_owned());
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/sources/papermc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a> PaperMCAPI<'a> {
version: &str,
build: &str,
) -> Result<Vec<Step>> {
let resolved_build = self.fetch_build(project, &version, build).await?;
let resolved_build = self.fetch_build(project, version, build).await?;

let download = resolved_build.downloads.get("application")
.ok_or(anyhow!("downloads['application'] missing for papermc project {project} {version}, build {build} ({})", resolved_build.build))?;
Expand Down
4 changes: 2 additions & 2 deletions src/api/sources/spigot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub struct SpigotAPI<'a>(pub &'a App);

impl<'a> SpigotAPI<'a> {
pub async fn fetch_api<T: DeserializeOwned>(&self, url: &str) -> Result<T> {
Ok(self
self
.0
.http_get_json(format!("{}/{url}", self.0.options.api_urls.spiget))
.await?)
.await
}

pub async fn fetch_resource(&self, id: &str) -> Result<SpigotResource> {
Expand Down
2 changes: 1 addition & 1 deletion src/api/sources/url/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub async fn resolve_steps_for_url(
};

Ok(vec![Step::Download {
url: url.into(),
url,
metadata,
}])
}
Expand Down
Loading

0 comments on commit c17c43a

Please sign in to comment.