Skip to content

Commit

Permalink
clippy && fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlan404 committed Aug 6, 2023
1 parent 78690ec commit 382522a
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 111 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ whats a semver? /s

### `0.3.1` (unreleased)

- Added [neoforge](https://neoforged.net/) server type
- Added [NeoForge](https://neoforged.net/) server type
- Added [Forge](https://forums.minecraftforge.net/) server type
- Added Downloadable type **Maven**
- Improved building process
- Fixed a bug on `mcman run` which messed up the output when server crashes
- Some downloadables now support variables

### `0.3.0`

Expand Down
4 changes: 3 additions & 1 deletion src/core/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ impl BuildContext {
}

let exit_status = child.wait()?;
stdout_process.await.context("Awaiting stdout proxy printing thread")?;
stdout_process
.await
.context("Awaiting stdout proxy printing thread")?;

if !exit_status.success() {
println!();
Expand Down
12 changes: 9 additions & 3 deletions src/core/serverjar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ impl BuildContext {
jar_name.clone()
} else {
"<in libraries>".to_owned()
}).dim()
})
.dim()
);
} else {
println!(
Expand All @@ -67,7 +68,8 @@ impl BuildContext {
jar_name.clone()
} else {
"<in libraries>".to_owned()
}).dim()
})
.dim()
);

let mut cmd_args = vec!["-jar", &installer_jar];
Expand Down Expand Up @@ -115,7 +117,11 @@ impl BuildContext {
}
}?;

self.startup_method = self.server.jar.get_startup_method(&self.http_client, &serverjar_name, &self.server.mc_version).await?;
self.startup_method = self
.server
.jar
.get_startup_method(&self.http_client, &serverjar_name, &self.server.mc_version)
.await?;

Ok(())
}
Expand Down
19 changes: 15 additions & 4 deletions src/model/downloadable/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Downloadable {

Self::Maven { version, .. } => {
map.insert("Name".to_owned(), self.get_md_link());
map.insert("Version".to_owned(), version.to_owned());
map.insert("Version".to_owned(), version.clone());
}

Self::Url {
Expand Down Expand Up @@ -190,8 +190,17 @@ impl Downloadable {
map.insert("Asset/File".to_owned(), artifact.clone());
}

Self::Maven { url, group, artifact, version, filename } => {
map.insert("Project/URL".to_owned(), format!("{group}.{artifact} - ({url})"));
Self::Maven {
url,
group,
artifact,
version,
filename,
} => {
map.insert(
"Project/URL".to_owned(),
format!("{group}.{artifact} - ({url})"),
);
map.insert("Version/Release".to_owned(), version.clone());
map.insert("Asset/File".to_owned(), filename.clone());
}
Expand All @@ -214,7 +223,9 @@ impl Downloadable {
"URL".to_string()
}
}
Self::Maven { group, artifact, .. } => {
Self::Maven {
group, artifact, ..
} => {
format!("Maven/{group}.{artifact}")
}
}
Expand Down
58 changes: 37 additions & 21 deletions src/model/downloadable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use anyhow::Result;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};

use crate::sources::maven::{get_maven_url, self};
use crate::sources::maven::{self, get_maven_url};
use crate::{model::Server, Source};

use crate::sources::{
curserinth::{ fetch_curserinth_filename, get_curserinth_url},
curserinth::{fetch_curserinth_filename, get_curserinth_url},
github::{download_github_release, fetch_github_release_filename, get_github_release_url},
jenkins::{ get_jenkins_download_url, get_jenkins_filename},
modrinth::{ fetch_modrinth_filename, get_modrinth_url},
jenkins::{get_jenkins_download_url, get_jenkins_filename},
modrinth::{fetch_modrinth_filename, get_modrinth_url},
spigot::{fetch_spigot_resource_latest_ver, get_spigot_url},
};
mod import_url;
Expand Down Expand Up @@ -112,9 +112,13 @@ impl Downloadable {
artifact,
} => Ok(get_jenkins_download_url(client, url, job, build, artifact).await?),

Self::Maven { url, group, artifact, version, filename } => {
Ok(get_maven_url(client, url, group, artifact, version, filename, mcver).await?)
}
Self::Maven {
url,
group,
artifact,
version,
filename,
} => Ok(get_maven_url(client, url, group, artifact, version, filename, mcver).await?),
}
}
}
Expand All @@ -128,16 +132,21 @@ impl Source for Downloadable {
filename_hint: Option<&str>,
) -> Result<reqwest::Response> {
match self {
Self::GithubRelease { repo, tag, asset } => {
Ok(download_github_release(repo, tag, asset, &server.mc_version, client, filename_hint).await?)
}

dl => {
Ok(client.get(dl.get_url(client, server, filename_hint).await?)
.send()
.await?
.error_for_status()?)
}
Self::GithubRelease { repo, tag, asset } => Ok(download_github_release(
repo,
tag,
asset,
&server.mc_version,
client,
filename_hint,
)
.await?),

dl => Ok(client
.get(dl.get_url(client, server, filename_hint).await?)
.send()
.await?
.error_for_status()?),
}
}

Expand Down Expand Up @@ -182,10 +191,17 @@ impl Source for Downloadable {
} => Ok(get_jenkins_filename(client, url, job, build, artifact)
.await?
.1),

Self::Maven { url, group, artifact, version, filename } => {
Ok(maven::get_maven_filename(client, url, group, artifact, version, filename, mcver).await?)
}

Self::Maven {
url,
group,
artifact,
version,
filename,
} => Ok(maven::get_maven_filename(
client, url, group, artifact, version, filename, mcver,
)
.await?),
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/model/servertype/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ impl ServerType {
loader: "latest".to_owned(),
installer: "latest".to_owned(),
},
2 => Self::NeoForge { loader: "latest".to_owned() },
3 => Self::Forge { loader: "latest".to_owned() },
2 => Self::NeoForge {
loader: "latest".to_owned(),
},
3 => Self::Forge {
loader: "latest".to_owned(),
},
_ => unreachable!(),
})
}
Expand Down
11 changes: 1 addition & 10 deletions src/model/servertype/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::Source;

use crate::model::Downloadable;
use crate::sources::{
fabric,
jenkins,
papermc,
purpur,
quilt,
vanilla,
neoforge,
forge,
};
use crate::sources::{fabric, forge, jenkins, neoforge, papermc, purpur, quilt, vanilla};

use super::{Server, StartupMethod};

Expand Down
4 changes: 2 additions & 2 deletions src/sources/forge.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Result, Context};
use anyhow::{anyhow, Context, Result};

use crate::util;

Expand Down Expand Up @@ -30,7 +30,7 @@ pub async fn get_versions_for(mcver: &str, client: &reqwest::Client) -> Result<V
pub async fn get_latest_version_for(mcver: &str, client: &reqwest::Client) -> Result<String> {
let loader_versions = get_versions_for(mcver, client).await?;

util::get_latest_semver(loader_versions).ok_or(anyhow!("No loader versions for {mcver}"))
util::get_latest_semver(&loader_versions).ok_or(anyhow!("No loader versions for {mcver}"))
}

pub async fn map_forge_version(
Expand Down
20 changes: 12 additions & 8 deletions src/sources/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ pub async fn fetch_github_release_asset(
"latest" => releases.first(),
id => releases.iter().find(|r| r.tag_name == id),
}
.ok_or(anyhow!("Github release with tag '{tag}' not found on repository '{repo}'"))?;
.ok_or(anyhow!(
"Github release with tag '{tag}' not found on repository '{repo}'"
))?;

let assets = &release.assets;

Expand All @@ -86,16 +88,18 @@ pub async fn fetch_github_release_asset(
id.to_owned()
};

assets.iter().find(|a| {
id == a.name
}).or(assets.iter().find(|a| {
a.name.contains(&id)
}))
assets
.iter()
.find(|a| id == a.name)
.or(assets.iter().find(|a| a.name.contains(&id)))
}
}
.ok_or(anyhow!("Github release asset with name '{asset}' on release '{}' not found", release.tag_name))?;
.ok_or(anyhow!(
"Github release asset with name '{asset}' on release '{}' not found",
release.tag_name
))?;

Ok(resolved_asset.to_owned())
Ok(resolved_asset.clone())
}

pub async fn fetch_github_release_filename(
Expand Down
38 changes: 20 additions & 18 deletions src/sources/maven.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{Result, anyhow};
use anyhow::{anyhow, Result};

pub fn get_metadata_url(url: &str, group_id: &str, artifact_id: &str) -> String {
format!(
Expand Down Expand Up @@ -76,7 +76,8 @@ pub async fn get_maven_filename(
) -> Result<String> {
let version = match_maven_version(client, url, group_id, artifact_id, version, mcver).await?;

let file = file.replace("${artifact}", artifact_id)
let file = file
.replace("${artifact}", artifact_id)
.replace("${version}", &version)
.replace("${mcversion}", mcver)
.replace("${mcver}", mcver);
Expand All @@ -100,22 +101,23 @@ pub async fn match_maven_version(

let version = match version {
"latest" => fetch_versions().await?.0,
id => if id.contains("$") {
let versions = fetch_versions().await?.1;
let id = id.replace("${artifact}", artifact_id)
.replace("${mcversion}", mcver)
.replace("${mcver}", mcver);
versions.iter().find(|v| {
v.to_owned() == &id
}).or_else(|| {
versions.iter().find(|v| {
v.contains(&id)
})
}).ok_or(anyhow!("Couldn't resolve maven artifact version"))?
.to_owned()
} else {
id.to_owned()
},
id => {
if id.contains('$') {
let versions = fetch_versions().await?.1;
let id = id
.replace("${artifact}", artifact_id)
.replace("${mcversion}", mcver)
.replace("${mcver}", mcver);
versions
.iter()
.find(|v| *v == &id)
.or_else(|| versions.iter().find(|v| v.contains(&id)))
.ok_or(anyhow!("Couldn't resolve maven artifact version"))?
.clone()
} else {
id.to_owned()
}
}
};

Ok(version)
Expand Down
6 changes: 3 additions & 3 deletions src/sources/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pub mod curserinth;
pub mod fabric;
pub mod forge;
pub mod github;
pub mod jenkins;
pub mod maven;
pub mod modrinth;
pub mod neoforge;
pub mod papermc;
pub mod purpur;
pub mod quilt;
pub mod spigot;
pub mod vanilla;
pub mod maven;
pub mod neoforge;
pub mod forge;
2 changes: 1 addition & 1 deletion src/sources/neoforge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub async fn get_latest_version_for(mcver: &str, client: &reqwest::Client) -> Re
.await
.context("Fetching NeoForge versions")?;

util::get_latest_semver(loader_versions).ok_or(anyhow!("No loader versions for {mcver}"))
util::get_latest_semver(&loader_versions).ok_or(anyhow!("No loader versions for {mcver}"))
}

pub async fn map_neoforge_version(
Expand Down
Loading

0 comments on commit 382522a

Please sign in to comment.