Skip to content

Commit

Permalink
Preliminary support for adding of multiple mods
Browse files Browse the repository at this point in the history
  • Loading branch information
theRookieCoder committed Feb 24, 2024
1 parent 091e839 commit 40a1043
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 62 deletions.
7 changes: 3 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ once_cell = "1.19"
fs_extra = "1.3"
ferinth = "2.10"
colored = "2.1"
libium = "1.26"
# libium = "1.26"
# libium = { path = "../libium" }
libium = { rev = "e11a80bc57c5cda6fa3605ba3b96a1b2563760f9", git = "https://github.com/gorilla-devs/libium" }
anyhow = "1.0"
furse = "1.5"
size = "0.4"
Expand Down
6 changes: 3 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ pub struct Ferium {

#[derive(Subcommand)]
pub enum SubCommands {
/// Add a mod to the profile
/// Add mods to the profile
Add {
/// The identifier of the mod/project/repository
/// The identifier(s) of the mod/project/repository
///
/// 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 GitHub identifier is the repository's full name, e.g. `gorilla-devs/ferium`.
identifier: String,
identifiers: Vec<String>,
/// Temporarily ignore game version and mod loader checks and add the mod anyway
#[clap(long, short, visible_alias = "override")]
force: bool,
Expand Down
101 changes: 48 additions & 53 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use libium::{
use octocrab::OctocrabBuilder;
use once_cell::sync::Lazy;
use std::{
collections::HashMap,
env::{var, var_os},
process::ExitCode,
};
Expand Down Expand Up @@ -166,69 +167,63 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
unreachable!();
}
SubCommands::Add {
identifier,
identifiers,
force,
ignore_game_version,
ignore_mod_loader,
} => {
let profile = get_active_profile(&mut config)?;
eprint!("Adding mod... ");
if let Ok(project_id) = identifier.parse() {
let name = libium::add::curseforge(
&curseforge,
project_id,
profile,
!force,
!ignore_game_version,
!ignore_mod_loader,
)
.await?;
println!("{} {}", *TICK, name.bold());
} else if identifier.split('/').count() == 2 {
let split = identifier.split('/').collect::<Vec<_>>();
let name = libium::add::github(
&github.build()?.repos(split[0], split[1]),
profile,
!force,
!ignore_game_version,
!ignore_mod_loader,
)
.await?;
println!("{} {}", *TICK, name.bold());
} else {
match libium::add::modrinth(
&modrinth,
&identifier,
profile,
!force,
!ignore_game_version,
!ignore_mod_loader,
)
.await
{
Ok((name, donation_urls)) => {
println!("{} {}", *TICK, name.bold());
match identifiers.len() {
0 => bail!("Must provide at least one identifier"),
1 => {
eprint!("Adding mod... ");
let name = libium::add::add_single(
&modrinth,
&curseforge,
&github.build()?,
profile,
&identifiers[0],
!force,
!ignore_game_version,
!ignore_mod_loader,
)
.await?;
println!("{} {}", *TICK, name.bold());
}
_ => {
eprint!("Fetching mod information... ");
let (successes, failures) = libium::add::add_multiple(
&modrinth,
&curseforge,
&github.build()?,
profile,
identifiers,
)
.await;
println!("{}", *TICK);

if !donation_urls.is_empty() {
if !successes.is_empty() {
println!(
"Successfully added {}",
successes.iter().map(|s| s.bold()).format(", ")
);
}
if !failures.is_empty() {
let mut grouped_errors = HashMap::new();
for (id, error) in failures {
grouped_errors
.entry(error.to_string())
.or_insert_with(Vec::new)
.push(id);
}
for (err, ids) in grouped_errors {
println!(
"Consider supporting the mod creator on {}",
donation_urls
.iter()
.map(|this| format!(
"{} ({})",
this.platform.bold(),
this.url.to_string().blue().underline()
))
.format(" or ")
"{}: {}",
err.red().bold(),
ids.iter().map(|s| s.italic()).format(", ")
);
}
}
Err(err) => {
if err.to_string() == ferinth::Error::InvalidIDorSlug.to_string() {
bail!("Invalid identifier")
}
bail!(err)
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ fn add_github() -> Result {
)
}

fn add_all() -> Result {
run_command(
vec!["add", "starlight", "591388", "CaffeineMC/sodium-fabric"],
Some("empty_profile"),
)
}

#[test]
fn modpack_add_modrinth() -> Result {
// Add Fabulously Optimised
Expand Down Expand Up @@ -178,7 +185,7 @@ fn already_added() {
assert!(run_command(vec!["add", "StArLiGhT"], Some("one_profile_full")).is_err());
assert!(run_command(vec!["add", "591388"], Some("one_profile_full")).is_err());
assert!(run_command(
vec!["add", "caffeinemc", "Sodium-Fabric"],
vec!["add", "caffeinemc/Sodium-Fabric"],
Some("one_profile_full")
)
.is_err());
Expand Down

0 comments on commit 40a1043

Please sign in to comment.