Skip to content

Commit 5691c95

Browse files
Don't mention ID in add error when only adding one mod, pull libium changes, and better filter CLI
1 parent d9a1017 commit 5691c95

File tree

8 files changed

+207
-195
lines changed

8 files changed

+207
-195
lines changed

Cargo.lock

Lines changed: 106 additions & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,17 @@ tokio = { version = "1.40", default-features = false, features = [
5050
"rt-multi-thread",
5151
"macros",
5252
] }
53-
rustls = { version = "0.23", default-features = false, features = ["ring"] }
5453
clap = { version = "4.5", features = ["derive"] }
5554
clap_complete = "4.5"
5655
serde_json = "1.0"
5756
indicatif = "0.17"
58-
octocrab = "0.40"
57+
octocrab = "0.41"
5958
fs_extra = "1.3"
6059
ferinth = "2.11"
6160
colored = "2.1"
6261
futures = "0.3"
6362
inquire = "0.7"
64-
libium = { git = "https://github.com/gorilla-devs/libium", rev = "01d3aebe6c21e93376143b49d4bbd3e0325cb411" }
63+
libium = { git = "https://github.com/gorilla-devs/libium", rev = "b7d2cd767b840313bc71dca643e4252c4e16dd3e" }
6564
# libium = { path = "../libium" }
6665
# libium = "1.32"
6766
anyhow = "1.0"

src/add.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ pub fn display_successes_failures(successes: &[String], failures: Vec<(String, E
99
"Successfully added".green(),
1010
successes.iter().map(|s| s.bold()).display(", ")
1111
);
12+
13+
// No need to print the ID again if there is only one
14+
} else if failures.len() == 1 {
15+
let err = &failures[0].1;
16+
return if matches!(err, libium::add::Error::AlreadyAdded) {
17+
println!("{}", err.to_string().yellow());
18+
false
19+
} else {
20+
println!("{}", err.to_string().red());
21+
true
22+
};
1223
}
1324

1425
let mut grouped_errors = HashMap::new();

src/cli.rs

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#![deny(missing_docs)]
22

3-
use clap::{Parser, Subcommand, ValueEnum, ValueHint};
3+
use clap::{Args, Parser, Subcommand, ValueEnum, ValueHint};
44
use clap_complete::Shell;
5-
use libium::config::{filters::ReleaseChannel, structs::ModLoader};
5+
use libium::config::{
6+
filters::{self, Filter},
7+
structs::ModLoader,
8+
};
69
use std::path::PathBuf;
710

811
#[derive(Parser)]
@@ -55,21 +58,8 @@ pub enum SubCommands {
5558
#[clap(long, short, visible_alias = "override")]
5659
force: bool,
5760

58-
#[clap(long, short = 'l', group = "loader")]
59-
mod_loader_prefer: Vec<ModLoader>,
60-
#[clap(long, group = "loader")]
61-
mod_loader_any: Vec<ModLoader>,
62-
63-
#[clap(long, short = 'v', group = "version")]
64-
game_version_strict: Vec<String>,
65-
#[clap(long, group = "version")]
66-
game_version_minor: Vec<String>,
67-
68-
#[clap(long, short = 'c')]
69-
release_channel: Option<ReleaseChannel>,
70-
71-
#[clap(long, short = 'n')]
72-
file_name: Option<String>,
61+
#[command(flatten)]
62+
filters: FilterArguments,
7363
},
7464
/// Scan the profile's output directory (or the specified directory) for mods and add them to the profile
7565
Scan {
@@ -258,6 +248,67 @@ pub enum ModpackSubCommands {
258248
Upgrade,
259249
}
260250

251+
#[derive(Args)]
252+
#[group(id = "loader", multiple = false)]
253+
// #[group(id = "version", multiple = false)]
254+
pub struct FilterArguments {
255+
#[clap(long, short = 'p')]
256+
pub override_profile: bool,
257+
258+
#[clap(long, short = 'l', group = "loader")]
259+
pub mod_loader_prefer: Vec<ModLoader>,
260+
#[clap(long, group = "loader")]
261+
pub mod_loader_any: Vec<ModLoader>,
262+
263+
#[clap(long, short = 'v', group = "version")]
264+
pub game_version_strict: Vec<String>,
265+
#[clap(long, group = "version")]
266+
pub game_version_minor: Vec<String>,
267+
268+
#[clap(long, short = 'c')]
269+
pub release_channel: Option<filters::ReleaseChannel>,
270+
271+
#[clap(long, short = 'n')]
272+
pub filename: Option<String>,
273+
#[clap(long, short = 't')]
274+
pub title: Option<String>,
275+
#[clap(long, short = 'd')]
276+
pub description: Option<String>,
277+
}
278+
279+
impl From<FilterArguments> for Vec<Filter> {
280+
fn from(value: FilterArguments) -> Self {
281+
let mut filters = vec![];
282+
283+
if !value.mod_loader_prefer.is_empty() {
284+
filters.push(Filter::ModLoaderPrefer(value.mod_loader_prefer));
285+
}
286+
if !value.mod_loader_any.is_empty() {
287+
filters.push(Filter::ModLoaderAny(value.mod_loader_any));
288+
}
289+
if !value.game_version_strict.is_empty() {
290+
filters.push(Filter::GameVersionStrict(value.game_version_strict));
291+
}
292+
if !value.game_version_minor.is_empty() {
293+
filters.push(Filter::GameVersionMinor(value.game_version_minor));
294+
}
295+
if let Some(release_channel) = value.release_channel {
296+
filters.push(Filter::ReleaseChannel(release_channel));
297+
}
298+
if let Some(regex) = value.filename {
299+
filters.push(Filter::Filename(regex));
300+
}
301+
if let Some(regex) = value.title {
302+
filters.push(Filter::Title(regex));
303+
}
304+
if let Some(regex) = value.description {
305+
filters.push(Filter::Description(regex));
306+
}
307+
308+
filters
309+
}
310+
}
311+
261312
#[derive(Clone, Copy, Default, ValueEnum)]
262313
pub enum Platform {
263314
#[default]

src/download.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use fs_extra::{
99
};
1010
use futures::{stream::FuturesUnordered, StreamExt as _};
1111
use indicatif::ProgressBar;
12-
use libium::{iter_ext::IterExt as _, upgrade::DownloadFile};
12+
use libium::{iter_ext::IterExt as _, upgrade::DownloadData};
1313
use std::{
1414
ffi::OsString,
1515
fs::{copy, create_dir_all, read_dir, remove_file},
@@ -26,10 +26,10 @@ use tokio::sync::Semaphore;
2626
/// - If the file is a `.part` file or if the move failed, the file will be deleted
2727
pub async fn clean(
2828
directory: &Path,
29-
to_download: &mut Vec<DownloadFile>,
29+
to_download: &mut Vec<DownloadData>,
3030
to_install: &mut Vec<(OsString, PathBuf)>,
3131
) -> Result<()> {
32-
let dupes = find_dupes_by_key(to_download, DownloadFile::filename);
32+
let dupes = find_dupes_by_key(to_download, DownloadData::filename);
3333
if !dupes.is_empty() {
3434
println!(
3535
"{}",
@@ -96,7 +96,7 @@ pub fn read_overrides(directory: &Path) -> Result<Vec<(OsString, PathBuf)>> {
9696
/// Download and install the files in `to_download` and `to_install` to `output_dir`
9797
pub async fn download(
9898
output_dir: PathBuf,
99-
to_download: Vec<DownloadFile>,
99+
to_download: Vec<DownloadData>,
100100
to_install: Vec<(OsString, PathBuf)>,
101101
) -> Result<()> {
102102
let progress_bar = Arc::new(Mutex::new(
@@ -128,7 +128,7 @@ pub async fn download(
128128
let _permit = semaphore.acquire_owned().await?;
129129

130130
let (length, filename) = downloadable
131-
.download(&client, &output_dir, |additional| {
131+
.download(client, &output_dir, |additional| {
132132
progress_bar
133133
.lock()
134134
.expect("Mutex poisoned")

src/main.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ fn main() -> ExitCode {
7575

7676
let cli = Ferium::parse();
7777

78-
let _ = rustls::crypto::ring::default_provider().install_default();
79-
8078
let mut builder = tokio::runtime::Builder::new_multi_thread();
8179
builder.enable_all();
8280
builder.thread_name("ferium-worker");
@@ -201,31 +199,22 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
201199
}
202200
}
203201

204-
let (successes, failures) = libium::add(profile, send_ids, !force).await?;
202+
let (successes, failures) =
203+
libium::add(profile, send_ids, !force, false, vec![]).await?;
205204
spinner.finish_and_clear();
206205

207206
did_add_fail = add::display_successes_failures(&successes, failures);
208207
}
209208
SubCommands::Add {
210209
identifiers,
211210
force,
212-
mod_loader_prefer,
213-
mod_loader_any,
214-
game_version_strict,
215-
game_version_minor,
216-
release_channel,
217-
file_name,
211+
filters,
218212
} => {
219213
let profile = get_active_profile(&mut config)?;
214+
let override_profile = filters.override_profile;
215+
let filters: Vec<_> = filters.into();
220216

221-
if identifiers.len() > 1
222-
&& (!mod_loader_prefer.is_empty()
223-
|| !mod_loader_any.is_empty()
224-
|| !game_version_strict.is_empty()
225-
|| !game_version_minor.is_empty()
226-
|| release_channel.is_some()
227-
|| file_name.is_some())
228-
{
217+
if identifiers.len() > 1 && !filters.is_empty() {
229218
bail!("Only configure filters when adding a single mod!")
230219
}
231220

@@ -236,6 +225,8 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
236225
.map(libium::add::parse_id)
237226
.collect_vec(),
238227
!force,
228+
override_profile,
229+
filters,
239230
)
240231
.await?;
241232

src/subcommands/modpack/upgrade.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use libium::{
1313
curseforge::structs::Manifest as CFManifest, modrinth::structs::Metadata as MRMetadata,
1414
read_file_from_zip, zip_extract,
1515
},
16-
upgrade::{DistributionDeniedError, DownloadFile},
16+
upgrade::{from_modpack_file, try_from_cf_file, DistributionDeniedError, DownloadData},
1717
CURSEFORGE_API, HOME,
1818
};
1919
use std::{
@@ -24,7 +24,7 @@ use std::{
2424
};
2525

2626
pub async fn upgrade(modpack: &'_ Modpack) -> Result<()> {
27-
let mut to_download: Vec<DownloadFile> = Vec::new();
27+
let mut to_download: Vec<DownloadData> = Vec::new();
2828
let mut to_install = Vec::new();
2929
let install_msg;
3030

@@ -61,8 +61,8 @@ pub async fn upgrade(modpack: &'_ Modpack) -> Result<()> {
6161
let mut tasks = FuturesUnordered::new();
6262
let mut msg_shown = false;
6363
for file in files {
64-
match TryInto::<DownloadFile>::try_into(file) {
65-
Ok(mut downloadable) => {
64+
match try_from_cf_file(file) {
65+
Ok((_, mut downloadable)) => {
6666
downloadable.output = PathBuf::from(
6767
if Path::new(&downloadable.filename())
6868
.extension()
@@ -129,7 +129,7 @@ pub async fn upgrade(modpack: &'_ Modpack) -> Result<()> {
129129
)?;
130130

131131
for file in metadata.files {
132-
to_download.push(file.into());
132+
to_download.push(from_modpack_file(file));
133133
}
134134

135135
install_msg = format!(

src/subcommands/upgrade.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use libium::{
1313
filters::ProfileParameters as _,
1414
structs::{ModLoader, Profile},
1515
},
16-
upgrade::{mod_downloadable, DownloadFile},
16+
upgrade::{mod_downloadable, DownloadData},
1717
};
1818
use std::{
1919
fs::read_dir,
@@ -26,7 +26,7 @@ use tokio::sync::Semaphore;
2626
///
2727
/// If an error occurs with a resolving task, instead of failing immediately,
2828
/// resolution will continue and the error return flag is set to true.
29-
pub async fn get_platform_downloadables(profile: &Profile) -> Result<(Vec<DownloadFile>, bool)> {
29+
pub async fn get_platform_downloadables(profile: &Profile) -> Result<(Vec<DownloadData>, bool)> {
3030
let to_download = Arc::new(Mutex::new(Vec::new()));
3131
let progress_bar = Arc::new(Mutex::new(
3232
ProgressBar::new(profile.mods.len() as u64).with_style(STYLE_NO.clone()),

0 commit comments

Comments
 (0)