Skip to content

Commit

Permalink
Sync code with dependencies and implement the new lints
Browse files Browse the repository at this point in the history
  • Loading branch information
theRookieCoder committed May 21, 2024
1 parent 9cc36d9 commit f17a60a
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Ferium {
/// You can also use the environment variable `GITHUB_TOKEN`.
#[clap(long, visible_alias = "gh")]
pub github_token: Option<String>,
/// Set a custom CurseForge API key.
/// Set a custom Curseforge API key.
/// You can also use the environment variable `CURSEFORGE_API_KEY`.
#[clap(long, visible_alias = "cf")]
pub curseforge_api_key: Option<String>,
Expand All @@ -39,7 +39,7 @@ pub enum SubCommands {
///
/// The Modrinth project ID is specified at the bottom of the left sidebar under 'Technical information'.
/// You can also use the project slug in the URL.
/// The CurseForge project ID is specified at the top of the right sidebar under 'About Project'.
/// The Curseforge project ID is specified at the top of the right sidebar under 'About Project'.
/// The GitHub identifier is the repository's full name, e.g. `gorilla-devs/ferium`.
identifiers: Vec<String>,
/// Temporarily ignore game version and mod loader checks and add the mod anyway
Expand Down Expand Up @@ -173,7 +173,7 @@ pub enum ModpackSubCommands {
///
/// The Modrinth project ID is specified at the bottom of the left sidebar under 'Technical information'.
/// You can also use the project slug for this.
/// The CurseForge project ID is specified at the top of the right sidebar under 'About Project'.
/// The Curseforge project ID is specified at the top of the right sidebar under 'About Project'.
identifier: String,
/// The Minecraft instance directory to install the modpack to
#[clap(long, short)]
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use libium::{
},
read_wrapper,
};
use octocrab::OctocrabBuilder;
use once_cell::sync::Lazy;
use std::{
collections::HashMap,
Expand Down Expand Up @@ -132,7 +131,7 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
};
}

let mut github = OctocrabBuilder::new();
let mut github = octocrab::OctocrabBuilder::new();
if let Some(token) = cli_app.github_token {
github = github.personal_token(token);
} else if let Ok(token) = var("GITHUB_TOKEN") {
Expand Down
14 changes: 3 additions & 11 deletions src/subcommands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use ferinth::{
use furse::{structures::mod_structs::Mod, Furse};
use itertools::{izip, Itertools};
use libium::config::structs::{ModIdentifier, Profile};
use octocrab::{
models::{repos::Release, Repository},
OctocrabBuilder,
};
use octocrab::models::{repos::Release, Repository};
use tokio::task::JoinSet;

enum Metadata {
Expand Down Expand Up @@ -56,13 +53,8 @@ pub async fn verbose(md: Ferinth, cf: Furse, profile: &mut Profile, markdown: bo
ModIdentifier::GitHubRepository((owner, repo)) => {
tasks.spawn(async {
Ok((
OctocrabBuilder::new()
.build()?
.repos(&owner, &repo)
.get()
.await?,
OctocrabBuilder::new()
.build()?
octocrab::instance().repos(&owner, &repo).get().await?,
octocrab::instance()
.repos(owner, repo)
.releases()
.list()
Expand Down
4 changes: 2 additions & 2 deletions src/subcommands/modpack/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub async fn curseforge(
let output_dir = match output_dir {
Some(some) => some,
None => pick_folder(
&get_minecraft_dir(),
get_minecraft_dir(),
"Pick an output directory",
"Output Directory",
)?
Expand Down Expand Up @@ -75,7 +75,7 @@ pub async fn modrinth(
let output_dir = match output_dir {
Some(some) => some,
None => pick_folder(
&get_minecraft_dir(),
get_minecraft_dir(),
"Pick an output directory",
"Output Directory",
)?
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/modpack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn check_output_directory(output_dir: &Path) -> Result<()> {
.interact()?
{
let backup_dir = pick_folder(
&HOME,
&*HOME,
"Where should the backup be made?",
"Output Directory",
)?
Expand Down
24 changes: 15 additions & 9 deletions src/subcommands/modpack/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use libium::{
HOME,
};
use std::{path::PathBuf, time::Duration};
use tokio::spawn;
use tokio::{io::BufReader, spawn};

#[allow(clippy::future_not_send)] // 3rd party library doesn't implement `Send`
pub async fn upgrade(modrinth: &Ferinth, curseforge: &Furse, modpack: &'_ Modpack) -> Result<()> {
Expand All @@ -44,9 +44,12 @@ pub async fn upgrade(modrinth: &Ferinth, curseforge: &Furse, modpack: &'_ Modpac
)
.await?;
let manifest: Manifest = serde_json::from_str(
&read_file_from_zip(modpack_file.try_clone().await?, "manifest.json")
.await?
.context("Does not contain manifest")?,
&read_file_from_zip(
BufReader::new(modpack_file.try_clone().await?),
"manifest.json",
)
.await?
.context("Does not contain manifest")?,
)?;
progress_bar.finish_and_clear();

Expand Down Expand Up @@ -113,7 +116,7 @@ pub async fn upgrade(modrinth: &Ferinth, curseforge: &Furse, modpack: &'_ Modpac
.join("ferium")
.join(".tmp")
.join(manifest.name);
extract_zip(modpack_file, &tmp_dir).await?;
extract_zip(BufReader::new(modpack_file), &tmp_dir).await?;
to_install = read_overrides(&tmp_dir.join(manifest.overrides))?;
}
}
Expand All @@ -133,9 +136,12 @@ pub async fn upgrade(modrinth: &Ferinth, curseforge: &Furse, modpack: &'_ Modpac
)
.await?;
let metadata: Metadata = serde_json::from_str(
&read_file_from_zip(modpack_file.try_clone().await?, "modrinth.index.json")
.await?
.context("Does not contain metadata file")?,
&read_file_from_zip(
BufReader::new(modpack_file.try_clone().await?),
"modrinth.index.json",
)
.await?
.context("Does not contain metadata file")?,
)?;
progress_bar.finish_and_clear();

Expand All @@ -158,7 +164,7 @@ pub async fn upgrade(modrinth: &Ferinth, curseforge: &Furse, modpack: &'_ Modpac
.join("ferium")
.join(".tmp")
.join(metadata.name);
extract_zip(modpack_file, &tmp_dir).await?;
extract_zip(BufReader::new(modpack_file), &tmp_dir).await?;
to_install = read_overrides(&tmp_dir.join("overrides"))?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/profile/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub async fn create(
.default(config.active_profile)
.interact()?
};
profile.mods = config.profiles[selection].mods.clone();
profile.mods.clone_from(&config.profiles[selection].mods);
}

println!(
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub async fn check_output_directory(output_dir: &PathBuf) -> Result<()> {
.interact()?
{
let backup_dir = pick_folder(
&HOME,
&*HOME,
"Where should the backup be made?",
"Output Directory",
)?
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ fn add_github() -> Result {
)
}

#[test]
fn add_all() -> Result {
run_command(
vec!["add", "starlight", "591388", "CaffeineMC/sodium-fabric"],
Expand Down

0 comments on commit f17a60a

Please sign in to comment.