Skip to content

Commit

Permalink
Add info subcommand to profile and modpack subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
theRookieCoder committed Jan 27, 2024
1 parent 35e4e35 commit 96439ff
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 62 deletions.
10 changes: 6 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ pub enum SubCommands {
markdown: bool,
},
/// Add, configure, delete, switch, list, or upgrade modpacks
#[clap(arg_required_else_help = true)]
Modpack {
#[clap(subcommand)]
subcommand: ModpackSubCommands,
subcommand: Option<ModpackSubCommands>,
},
/// Create, configure, delete, switch, or list profiles
#[clap(arg_required_else_help = true)]
Profile {
#[clap(subcommand)]
subcommand: ProfileSubCommands,
subcommand: Option<ProfileSubCommands>,
},
/// Remove mods and repositories from the profile.
/// Optionally, provide a list of names or IDs of the mods to remove.
Expand Down Expand Up @@ -140,6 +138,8 @@ pub enum ProfileSubCommands {
/// The name of the profile to delete
profile_name: Option<String>,
},
/// Show information about the current profile
Info,
/// List all the profiles with their data
List,
/// Switch between different profiles.
Expand Down Expand Up @@ -187,6 +187,8 @@ pub enum ModpackSubCommands {
/// The name of the modpack to delete
modpack_name: Option<String>,
},
/// Show information about the current modpack
Info,
/// List all the modpacks
List,
/// Switch between different modpacks.
Expand Down
34 changes: 23 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ async fn actual_main(cli_app: Ferium) -> Result<()> {
}
}
}
SubCommands::Modpack { subcommand } => match subcommand {
SubCommands::Modpack { subcommand } => {
let subcommand = subcommand.unwrap_or(ModpackSubCommands::Info);
match subcommand {
ModpackSubCommands::Add {
identifier,
output_dir,
Expand Down Expand Up @@ -328,11 +330,13 @@ async fn actual_main(cli_app: Ferium) -> Result<()> {
ModpackSubCommands::Delete { modpack_name } => {
subcommands::modpack::delete(&mut config, modpack_name)?;
}
ModpackSubCommands::List => {
if config.modpacks.is_empty() {
bail!("There are no modpacks configured, add a modpack using `ferium modpack add`")
ModpackSubCommands::Info => {
subcommands::modpack::info(get_active_modpack(&mut config)?, true);
}
subcommands::modpack::list(&config);
ModpackSubCommands::List => {
for (i, modpack) in config.modpacks.iter().enumerate() {
subcommands::modpack::info(modpack, i == config.active_modpack);
}
}
ModpackSubCommands::Switch { modpack_name } => {
subcommands::modpack::switch(&mut config, modpack_name)?;
Expand All @@ -345,9 +349,12 @@ async fn actual_main(cli_app: Ferium) -> Result<()> {
get_active_modpack(&mut config)?,
)
.await?;
}
}
};
},
SubCommands::Profile { subcommand } => match subcommand {
SubCommands::Profile { subcommand } => {
let subcommand = subcommand.unwrap_or(ProfileSubCommands::Info);
match subcommand {
ProfileSubCommands::Configure {
game_version,
mod_loader,
Expand Down Expand Up @@ -387,15 +394,20 @@ async fn actual_main(cli_app: Ferium) -> Result<()> {
ProfileSubCommands::Delete { profile_name } => {
subcommands::profile::delete(&mut config, profile_name)?;
}
ProfileSubCommands::Info => {
subcommands::profile::info(get_active_profile(&mut config)?, true);
}

ProfileSubCommands::List => {
if config.profiles.is_empty() {
bail!("There are no profiles configured, create a profile using `ferium profile create`")
for (i, profile) in config.profiles.iter().enumerate() {
subcommands::profile::info(profile, i == config.active_profile);
}
}
subcommands::profile::list(&config);
}

ProfileSubCommands::Switch { profile_name } => {
subcommands::profile::switch(&mut config, profile_name)?;
}
};
},
SubCommands::Remove { mod_names } => {
let profile = get_active_profile(&mut config)?;
Expand Down
21 changes: 21 additions & 0 deletions src/subcommands/modpack/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use colored::Colorize;
use libium::config::structs::{Modpack, ModpackIdentifier};

pub fn info(modpack: &Modpack, active: bool) {
println!(
"{}{}
\r Output directory: {}
\r Identifier: {}
\r Install Overrides: {}\n",
modpack.name.bold(),
if active { " *" } else { "" },
modpack.output_dir.display().to_string().blue().underline(),
match &modpack.identifier {
ModpackIdentifier::CurseForgeModpack(id) =>
format!("{:10} {}", "CurseForge".red(), id.to_string().dimmed()),
ModpackIdentifier::ModrinthModpack(id) =>
format!("{:10} {}", "Modrinth".green(), id.dimmed()),
},
modpack.install_overrides
);
}
23 changes: 0 additions & 23 deletions src/subcommands/modpack/list.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/subcommands/modpack/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pub mod add;
mod configure;
mod delete;
mod list;
mod info;
mod switch;
mod upgrade;
pub use configure::configure;
pub use delete::delete;
pub use list::list;
pub use info::info;
pub use switch::switch;
pub use upgrade::upgrade;

Expand Down
18 changes: 18 additions & 0 deletions src/subcommands/profile/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use colored::Colorize;
use libium::config::structs::Profile;

pub fn info(profile: &Profile, active: bool) {
println!(
"{}{}
\r Output directory: {}
\r Minecraft Version: {}
\r Mod Loader: {}
\r Mods: {}\n",
profile.name.bold(),
if active { " *" } else { "" },
profile.output_dir.display().to_string().blue().underline(),
profile.game_version.green(),
format!("{:?}", profile.mod_loader).purple(),
profile.mods.len().to_string().yellow(),
);
}
20 changes: 0 additions & 20 deletions src/subcommands/profile/list.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/subcommands/profile/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mod configure;
mod create;
mod delete;
mod list;
mod info;
mod switch;
pub use configure::configure;
pub use create::create;
pub use delete::delete;
pub use list::list;
pub use info::info;
pub use switch::switch;

use crate::THEME;
Expand Down

0 comments on commit 96439ff

Please sign in to comment.