Skip to content

Commit 3471e79

Browse files
Fix dependency adding bug and 2 QOL enchancements
1 parent d060a21 commit 3471e79

File tree

7 files changed

+95
-56
lines changed

7 files changed

+95
-56
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog for Ferium
22

3+
## `v3.28.6`
4+
### 11.05.2022
5+
6+
- `add-github` now accepts the `theRookieCoder/ferium` format (only one argument)
7+
- This makes it easier to copy paste the name from the URL
8+
- Fixed a bug when adding dependencies
9+
- Improved the non-verbose list command by showing the source and identifier
10+
311
## `v3.28.5`
412
### 11.05.2022
513

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ferium"
3-
version = "3.28.5"
3+
version = "3.28.6"
44
edition = "2021"
55
authors = ["Ilesh Thiada (theRookieCoder) <[email protected]>", "薛詠謙 (KyleUltimate)", "Daniel Hauck (SolidTux)"]
66
description = "Ferium is a CLI program for managing Minecraft mods from Modrinth, CurseForge, and Github Releases"

src/cli.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ pub enum SubCommands {
3636
},
3737
#[clap(about("Add a GitHub repository to the profile"))]
3838
AddGithub {
39-
#[clap(help("The repository owner's username"))]
40-
owner: String,
41-
#[clap(help("The name of the repository"))]
39+
#[clap(help("The full name of the repository, e.g. `theRookieCoder/ferium`"))]
4240
name: String,
4341
#[clap(long)]
4442
#[clap(help("Whether the game version should be checked for this mod"))]

src/main.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use ferinth::Ferinth;
1010
use furse::Furse;
1111
use indicatif::ProgressStyle;
1212
use lazy_static::lazy_static;
13-
use libium::config;
13+
use libium::config::{self, structs::ModIdentifier};
1414
use octocrab::OctocrabBuilder;
1515
use std::sync::Arc;
1616
use subcommands::{add, upgrade};
@@ -124,14 +124,17 @@ async fn actual_main(cli_app: Ferium) -> Result<()> {
124124
.await?;
125125
},
126126
SubCommands::AddGithub {
127-
owner,
128127
name,
129128
dont_check_game_version,
130129
dont_check_mod_loader,
131130
} => {
132131
check_internet().await?;
132+
let name = name.split('/').collect::<Vec<_>>();
133+
if name.len() != 2 {
134+
bail!("Invalid repository name")
135+
}
133136
add::github(
134-
github.repos(owner, name),
137+
github.repos(name[0], name[1]),
135138
profile,
136139
Some(!dont_check_game_version),
137140
Some(!dont_check_mod_loader),
@@ -159,7 +162,6 @@ async fn actual_main(cli_app: Ferium) -> Result<()> {
159162
check_internet().await?;
160163
let mut tasks = Vec::new();
161164
for mod_ in &profile.mods {
162-
use config::structs::ModIdentifier;
163165
match &mod_.identifier {
164166
ModIdentifier::CurseForgeProject(project_id) => tasks.push(spawn(
165167
subcommands::list::curseforge(curseforge.clone(), *project_id),
@@ -177,7 +179,22 @@ async fn actual_main(cli_app: Ferium) -> Result<()> {
177179
}
178180
} else {
179181
for mod_ in &profile.mods {
180-
println!("{}", mod_.name);
182+
println!(
183+
"{:45} {:10} {}",
184+
mod_.name.bold(),
185+
match &mod_.identifier {
186+
ModIdentifier::CurseForgeProject(_) => "CurseForge".red(),
187+
ModIdentifier::ModrinthProject(_) => "Modrinth".green(),
188+
ModIdentifier::GitHubRepository(_) => "GitHub".purple(),
189+
},
190+
match &mod_.identifier {
191+
ModIdentifier::CurseForgeProject(id) => id.to_string(),
192+
ModIdentifier::ModrinthProject(id) => id.into(),
193+
ModIdentifier::GitHubRepository(name) =>
194+
format!("{}/{}", name.0, name.1),
195+
}
196+
.dimmed()
197+
);
181198
}
182199
}
183200
},

src/subcommands/add.rs

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use crate::{THEME, TICK};
2-
use anyhow::{anyhow, Result};
2+
use anyhow::{anyhow, bail, Result};
33
use dialoguer::Confirm;
44
use ferinth::structures::version_structs::DependencyType;
55
use ferinth::Ferinth;
66
use furse::{structures::file_structs::FileRelationType, Furse};
7-
use libium::{add, config, upgrade};
7+
use libium::{
8+
add,
9+
config::{self, structs::ModIdentifier},
10+
upgrade,
11+
};
812
use octocrab::repos::RepoHandler;
913
use std::sync::Arc;
1014

@@ -68,28 +72,36 @@ pub async fn modrinth(
6872
} else {
6973
break;
7074
};
71-
// Check if the dependency has already been added
72-
if !profile.mods.iter().any(|mod_| {
73-
config::structs::ModIdentifier::ModrinthProject(id.clone()) == mod_.identifier
74-
}) {
75-
// If it's required, add it without asking
76-
if dependency.dependency_type == DependencyType::Required {
77-
eprint!("Adding required dependency... ");
75+
// If it's required, add it without asking
76+
if dependency.dependency_type == DependencyType::Required {
77+
eprint!("Adding required dependency... ");
78+
match add::modrinth(modrinth.clone(), &id, profile, None, None).await {
79+
Ok(project) => println!("{} ({})", *TICK, project.title),
80+
Err(err) => {
81+
if matches!(err, add::Error::AlreadyAdded) {
82+
println!("{} Already added", *TICK);
83+
} else {
84+
bail!(err);
85+
}
86+
},
87+
};
88+
} else if dependency.dependency_type == DependencyType::Optional {
89+
let project = modrinth.get_project(&id).await?;
90+
// If it is not already added:
91+
if profile.mods.iter().any(|mod_| {
92+
mod_.name == project.title
93+
|| ModIdentifier::ModrinthProject(id.clone()) == mod_.identifier
94+
// And the user wants to add it:
95+
}) && Confirm::with_theme(&*THEME)
96+
.with_prompt(format!(
97+
"Add optional dependency {} (https://modrinth.com/mod/{})?",
98+
project.title, project.slug
99+
))
100+
.interact()?
101+
{
102+
eprint!("Adding optional dependency... ");
78103
let project = add::modrinth(modrinth.clone(), &id, profile, None, None).await?;
79104
println!("{} ({})", *TICK, project.title);
80-
} else if dependency.dependency_type == DependencyType::Optional {
81-
let project = modrinth.get_project(&id).await?;
82-
let should_add = Confirm::with_theme(&*THEME)
83-
.with_prompt(format!(
84-
"Add optional dependency {} (https://modrinth.com/mod/{})?",
85-
project.title, project.slug
86-
))
87-
.interact()?;
88-
if should_add {
89-
eprint!("Adding optional dependency... ");
90-
let project = add::modrinth(modrinth.clone(), &id, profile, None, None).await?;
91-
println!("{} ({})", *TICK, project.title);
92-
}
93105
}
94106
}
95107
}
@@ -125,31 +137,35 @@ pub async fn curseforge(
125137
println!("{} ({})", *TICK, project.name);
126138
for dependency in &latest_file.dependencies {
127139
let id = dependency.mod_id;
128-
// Check if the dependency has already been added
129-
if !profile
130-
.mods
131-
.iter()
132-
.any(|mod_| config::structs::ModIdentifier::CurseForgeProject(id) == mod_.identifier)
133-
{
134-
// If it's required, add it without asking
135-
if dependency.relation_type == FileRelationType::RequiredDependency {
136-
eprint!("Adding required dependency... ");
140+
// If it's required, add it without asking
141+
if dependency.relation_type == FileRelationType::RequiredDependency {
142+
eprint!("Adding required dependency... ");
143+
match add::curseforge(curseforge.clone(), id, profile, None, None).await {
144+
Ok(project) => println!("{} ({})", *TICK, project.name),
145+
Err(err) => {
146+
if matches!(err, add::Error::AlreadyAdded) {
147+
println!("{} Already added", *TICK);
148+
} else {
149+
bail!(err);
150+
}
151+
},
152+
};
153+
} else if dependency.relation_type == FileRelationType::OptionalDependency {
154+
let project = curseforge.get_mod(id).await?;
155+
// If it is not already added:
156+
if !profile.mods.iter().any(|mod_| {
157+
mod_.name == project.name || ModIdentifier::CurseForgeProject(id) == mod_.identifier
158+
// And the user wants to add it:
159+
}) && Confirm::with_theme(&*THEME)
160+
.with_prompt(format!(
161+
"Add optional dependency {} ({})?",
162+
project.name, project.links.website_url
163+
))
164+
.interact()?
165+
{
166+
eprint!("Adding optional dependency... ");
137167
let project = add::curseforge(curseforge.clone(), id, profile, None, None).await?;
138168
println!("{} ({})", *TICK, project.name);
139-
} else if dependency.relation_type == FileRelationType::OptionalDependency {
140-
let project = curseforge.get_mod(id).await?;
141-
let should_add = Confirm::with_theme(&*THEME)
142-
.with_prompt(format!(
143-
"Add optional dependency {} ({})?",
144-
project.name, project.links.website_url
145-
))
146-
.interact()?;
147-
if should_add {
148-
eprint!("Adding optional dependency... ");
149-
let project =
150-
add::curseforge(curseforge.clone(), id, profile, None, None).await?;
151-
println!("{} ({})", *TICK, project.name);
152-
}
153169
}
154170
}
155171
}

tests/integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn add_curseforge() -> Result {
141141
fn add_github() -> Result {
142142
// Add Sodium to config
143143
run_command(
144-
vec!["add-github", "CaffeineMC", "sodium-fabric"],
144+
vec!["add-github", "CaffeineMC/sodium-fabric"],
145145
Some("empty_profile"),
146146
)
147147
}

0 commit comments

Comments
 (0)