Skip to content

Commit

Permalink
Begin migrating more of the adding code to libium
Browse files Browse the repository at this point in the history
  • Loading branch information
theRookieCoder committed Jan 26, 2024
1 parent 340470c commit 5a31bac
Show file tree
Hide file tree
Showing 10 changed files with 404 additions and 739 deletions.
613 changes: 315 additions & 298 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,29 @@ default = ["gui"]
gui = ["libium/gui"]

[dependencies]
octocrab = { version = "0.29", default-features = false, features = ["rustls"] }
octocrab = { version = "0.30", default-features = false, features = [
"rustls",
"rustls-webpki-tokio",
] }
reqwest = { version = "0.11", default-features = false, features = [
"rustls-tls",
] }
tokio = { version = "1.29", default-features = false, features = [
tokio = { version = "1.32", default-features = false, features = [
"rt-multi-thread",
"macros",
] }
clap = { version = "4.3", features = ["derive"] }
clap_complete = "4.3"
clap = { version = "4.4", features = ["derive"] }
clap_complete = "4.4"
serde_json = "1.0"
dialoguer = "0.10"
dialoguer = "0.11"
indicatif = "0.17"
itertools = "0.11"
once_cell = "1.18"
fs_extra = "1.3"
colored = "2.0"
ferinth = "2.9"
libium = "1.23"
# libium = "1.23"
libium = { path = "../libium" }
anyhow = "1.0"
furse = "1.5"
size = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The `nogui` versions do not need this as they won't have a GUI folder picker, ma
> From-source builds will install the Rust toolchain and GCC
| Installation method | GUI file dialogue | No GUI |
| ----------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------- |
|-------------------------------------------------|-------------------------------------------------------------------------|-------------------------------------------------------------|
| Install pre-built binaries from GitHub Releases | **[ferium-gui-bin](https://aur.archlinux.org/packages/ferium-gui-bin)** | [ferium-bin](https://aur.archlinux.org/packages/ferium-bin) |
| Build from source at the latest tag | [ferium-gui](https://aur.archlinux.org/packages/ferium-gui) | [ferium](https://aur.archlinux.org/packages/ferium) |
| Build from source using the latest commit | [ferium-gui-git](https://aur.archlinux.org/packages/ferium-gui-git) | [ferium-git](https://aur.archlinux.org/packages/ferium-git) |
Expand Down
1 change: 0 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ install-dev:
# Delete all build and test artefacts
clean:
cargo clean
rm -rf
rm -rf tests/mods
rm -rf tests/md_modpack
rm -rf tests/cf_modpack
Expand Down
68 changes: 27 additions & 41 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![deny(missing_docs)]

use clap::{clap_derive::ValueEnum, Parser, Subcommand, ValueHint};
use clap::{Parser, Subcommand, ValueHint};
use clap_complete::Shell;
use libium::config::structs::ModLoader;
use std::path::PathBuf;
Expand All @@ -12,23 +12,23 @@ use std::path::PathBuf;
pub struct Ferium {
#[clap(subcommand)]
pub subcommand: SubCommands,
#[clap(long, short)]
/// Sets the number of worker threads the tokio runtime will use.
/// You can also use the environment variable `TOKIO_WORKER_THREADS`.
#[clap(long, short)]
pub threads: Option<usize>,
#[clap(long)]
/// Set a GitHub personal access token for increasing the GitHub API rate limit.
/// You can also use the environment variable `GITHUB_TOKEN`.
pub github_token: Option<String>,
#[clap(long)]
pub github_token: Option<String>,
/// Set a custom CurseForge API key.
/// You can also use the environment variable `CURSEFORGE_API_KEY`.
#[clap(long)]
pub curseforge_api_key: Option<String>,
#[clap(long, short)]
#[clap(value_hint(ValueHint::FilePath))]
/// Set the file to read the config from.
/// This does not change the `cache` and `tmp` directories.
/// You can also use the environment variable `CONFIG_FILE`.
#[clap(long, short)]
#[clap(value_hint(ValueHint::FilePath))]
pub config_file: Option<PathBuf>,
}

Expand All @@ -43,43 +43,39 @@ pub enum SubCommands {
/// 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,
#[clap(long)]
/// The game version will not be checked for this mod
dont_check_game_version: bool,
#[clap(long)]
dont_check_game_version: bool,
/// The mod loader will not be checked for this mod
dont_check_mod_loader: bool,
#[clap(long)]
#[clap(value_enum)]
/// Select which dependencies should be added
dependencies: Option<DependencyLevel>,
dont_check_mod_loader: bool,
},
/// Print shell auto completions for the specified shell
Complete {
#[clap(value_enum)]
/// The shell to generate auto completions for
#[clap(value_enum)]
shell: Shell,
},
/// List all the mods in the profile, and with some their metadata if verbose
List {
#[clap(long, short)]
/// Show additional information about the mod
verbose: bool,
#[clap(long, short)]
verbose: bool,
/// Output information in markdown format and alphabetical order
///
/// Useful for creating modpack mod lists.
/// Complements the verbose flag.
#[clap(long, short)]
markdown: bool,
},
#[clap(arg_required_else_help = true)]
/// Add, configure, delete, switch, list, or upgrade modpacks
#[clap(arg_required_else_help = true)]
Modpack {
#[clap(subcommand)]
subcommand: ModpackSubCommands,
},
#[clap(arg_required_else_help = true)]
/// Create, configure, delete, switch, or list profiles
#[clap(arg_required_else_help = true)]
Profile {
#[clap(subcommand)]
subcommand: ProfileSubCommands,
Expand All @@ -99,43 +95,43 @@ pub enum ProfileSubCommands {
/// Configure the current profile's name, Minecraft version, mod loader, and output directory.
/// Optionally, provide the settings to change as arguments.
Configure {
#[clap(long, short = 'v')]
/// The Minecraft version to check compatibility for
#[clap(long, short = 'v')]
game_version: Option<String>,
/// The mod loader to check compatibility for
#[clap(long, short)]
#[clap(value_enum)]
/// The mod loader to check compatibility for
mod_loader: Option<ModLoader>,
#[clap(long, short)]
/// The name of the profile
#[clap(long, short)]
name: Option<String>,
/// The directory to output mods to
#[clap(long, short)]
#[clap(value_hint(ValueHint::DirPath))]
/// The directory to output mods to
output_dir: Option<PathBuf>,
},
/// Create a new profile.
/// Optionally, provide the settings as arguments.
/// Use the import flag to import mods from another profile.
Create {
#[clap(long, short)]
#[allow(clippy::option_option)]
/// Copy over the mods from an existing profile.
/// Optionally, provide the name of the profile to import mods from.
#[clap(long, short)]
#[allow(clippy::option_option)]
import: Option<Option<String>>,
#[clap(long, short = 'v')]
/// The Minecraft version to check compatibility for
#[clap(long, short = 'v')]
game_version: Option<String>,
/// The mod loader to check compatibility for
#[clap(long, short)]
#[clap(value_enum)]
/// The mod loader to check compatibility for
mod_loader: Option<ModLoader>,
#[clap(long, short)]
/// The name of the profile
#[clap(long, short)]
name: Option<String>,
/// The directory to output mods to
#[clap(long, short)]
#[clap(value_hint(ValueHint::DirPath))]
/// The directory to output mods to
output_dir: Option<PathBuf>,
},
/// Delete a profile.
Expand Down Expand Up @@ -164,25 +160,25 @@ pub enum ModpackSubCommands {
/// 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'.
identifier: String,
/// The Minecraft instance directory to install the modpack to
#[clap(long, short)]
#[clap(value_hint(ValueHint::DirPath))]
/// The Minecraft instance directory to install the modpack to
output_dir: Option<PathBuf>,
#[clap(long, short)]
/// Whether to install the modpack's overrides to the output directory.
/// This will override existing files when upgrading.
#[clap(long, short)]
install_overrides: Option<bool>,
},
/// Configure the current modpack's output directory and installation of overrides.
/// Optionally, provide the settings to change as arguments.
Configure {
/// The Minecraft instance directory to install the modpack to
#[clap(long, short)]
#[clap(value_hint(ValueHint::DirPath))]
/// The Minecraft instance directory to install the modpack to
output_dir: Option<PathBuf>,
#[clap(long, short)]
/// Whether to install the modpack's overrides to the output directory.
/// This will override existing files when upgrading.
#[clap(long, short)]
install_overrides: Option<bool>,
},
/// Delete a modpack.
Expand All @@ -202,13 +198,3 @@ pub enum ModpackSubCommands {
/// Download and install the latest version of the modpack
Upgrade,
}

#[derive(Clone, PartialEq, Eq, ValueEnum)]
pub enum DependencyLevel {
/// Do not add any dependencies
None,
/// Add only required dependencies
Required,
/// Add all dependencies
All,
}
71 changes: 45 additions & 26 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use dialoguer::theme::ColorfulTheme;
use ferinth::Ferinth;
use furse::Furse;
use indicatif::ProgressStyle;
use itertools::Itertools;
use libium::config::{
self,
structs::{Config, ModIdentifier, Modpack, Profile},
Expand Down Expand Up @@ -131,54 +132,71 @@ async fn actual_main(cli_app: Ferium) -> Result<()> {
identifier,
dont_check_game_version,
dont_check_mod_loader,
dependencies,
} => {
let profile = get_active_profile(&mut config)?;
check_internet().await?;
eprint!("Adding mod... ");
if let Ok(project_id) = identifier.parse::<i32>() {
subcommands::add::curseforge(
let name = libium::add::curseforge(
&curseforge,
project_id,
profile,
Some(!dont_check_game_version),
Some(!dont_check_mod_loader),
dependencies,
)
.await?;
println!("{} {}", *TICK, name.bold());
} else if identifier.split('/').count() == 2 {
let split = identifier.split('/').collect::<Vec<_>>();
subcommands::add::github(
github.build()?.repos(split[0], split[1]),
let name = libium::add::github(
&github.build()?.repos(split[0], split[1]),
profile,
Some(!dont_check_game_version),
Some(!dont_check_mod_loader),
)
.await?;
} else if let Err(err) = subcommands::add::modrinth(
&modrinth,
&identifier,
profile,
Some(!dont_check_game_version),
Some(!dont_check_mod_loader),
dependencies,
)
.await
{
return Err(
if err.to_string() == ferinth::Error::InvalidIDorSlug.to_string() {
anyhow!("Invalid indentifier")
} else {
err
},
);
println!("{} {}", *TICK, name.bold());
} else {
match libium::add::modrinth(
&modrinth,
&identifier,
profile,
Some(!dont_check_game_version),
Some(!dont_check_mod_loader),
)
.await
{
Ok((name, donation_urls)) => {
println!("{} {}", *TICK, name.bold());

if !donation_urls.is_empty() {
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(err) => {
if err.to_string() == ferinth::Error::InvalidIDorSlug.to_string() {
bail!("Invalid identifier")
}
bail!(err)
}
}
}
}
SubCommands::List { verbose, markdown } => {
let profile = get_active_profile(&mut config)?;
check_empty_profile(profile)?;
if verbose {
check_internet().await?;
let github = github.build()?;
let mut tasks = JoinSet::new();
let mut mr_ids = Vec::<&str>::new();
for mod_ in &profile.mods {
Expand All @@ -192,7 +210,8 @@ async fn actual_main(cli_app: Ferium) -> Result<()> {
.await?;
}
ModIdentifier::GitHubRepository(full_name) => {
subcommands::list::github_md(&github, full_name.clone()).await?;
subcommands::list::github_md(&github.build()?, full_name.clone())
.await?;
}
};
} else {
Expand All @@ -206,7 +225,7 @@ async fn actual_main(cli_app: Ferium) -> Result<()> {
ModIdentifier::ModrinthProject(project_id) => mr_ids.push(project_id),
ModIdentifier::GitHubRepository(full_name) => {
tasks.spawn(subcommands::list::github(
github.clone(),
github.build()?.clone(),
full_name.clone(),
));
}
Expand Down Expand Up @@ -289,7 +308,7 @@ async fn actual_main(cli_app: Ferium) -> Result<()> {
{
return Err(
if err.to_string() == ferinth::Error::InvalidIDorSlug.to_string() {
anyhow!("Invalid indentifier")
anyhow!("Invalid identifier")
} else {
err
},
Expand Down
Loading

0 comments on commit 5a31bac

Please sign in to comment.