Skip to content

Commit 15e08f9

Browse files
Add argument for profile/modpack to switch to when deleting
Also add the formatting to the picker for deletion too
1 parent 78864c7 commit 15e08f9

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

src/cli.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ pub enum ProfileSubCommands {
150150
Delete {
151151
/// The name of the profile to delete
152152
profile_name: Option<String>,
153+
/// The name of the profile to switch to afterwards
154+
#[clap(long, short)]
155+
switch_to: Option<String>,
153156
},
154157
/// Show information about the current profile
155158
Info,
@@ -201,6 +204,9 @@ pub enum ModpackSubCommands {
201204
Delete {
202205
/// The name of the modpack to delete
203206
modpack_name: Option<String>,
207+
/// The name of the profile to switch to afterwards
208+
#[clap(long, short)]
209+
switch_to: Option<String>,
204210
},
205211
/// Show information about the current modpack
206212
Info,

src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,11 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
361361
install_overrides,
362362
)?;
363363
}
364-
ModpackSubCommands::Delete { modpack_name } => {
365-
subcommands::modpack::delete(&mut config, modpack_name)?;
364+
ModpackSubCommands::Delete {
365+
modpack_name,
366+
switch_to,
367+
} => {
368+
subcommands::modpack::delete(&mut config, modpack_name, switch_to)?;
366369
}
367370
ModpackSubCommands::Info => {
368371
subcommands::modpack::info(get_active_modpack(&mut config)?, true);
@@ -436,8 +439,11 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
436439
)
437440
.await?;
438441
}
439-
ProfileSubCommands::Delete { profile_name } => {
440-
subcommands::profile::delete(&mut config, profile_name)?;
442+
ProfileSubCommands::Delete {
443+
profile_name,
444+
switch_to,
445+
} => {
446+
subcommands::profile::delete(&mut config, profile_name, switch_to)?;
441447
}
442448
ProfileSubCommands::Info => {
443449
subcommands::profile::info(get_active_profile(&mut config)?, true);

src/subcommands/modpack/delete.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
use super::switch;
22
use crate::THEME;
33
use anyhow::{bail, Result};
4+
use colored::Colorize;
45
use dialoguer::Select;
5-
use libium::config::structs::Config;
6+
use libium::config::structs::{Config, ModpackIdentifier};
67

7-
pub fn delete(config: &mut Config, modpack_name: Option<String>) -> Result<()> {
8+
pub fn delete(
9+
config: &mut Config,
10+
modpack_name: Option<String>,
11+
switch_to: Option<String>,
12+
) -> Result<()> {
813
// If the modpack name has been provided as an option
914
let selection = if let Some(modpack_name) = modpack_name {
1015
match config
@@ -19,7 +24,18 @@ pub fn delete(config: &mut Config, modpack_name: Option<String>) -> Result<()> {
1924
let modpack_names = config
2025
.modpacks
2126
.iter()
22-
.map(|modpack| &modpack.name)
27+
.map(|modpack| {
28+
format!(
29+
"{} {}",
30+
match &modpack.identifier {
31+
ModpackIdentifier::CurseForgeModpack(id) =>
32+
format!("{} {:8}", "CF".red(), id.to_string().dimmed()),
33+
ModpackIdentifier::ModrinthModpack(id) =>
34+
format!("{} {:8}", "MR".green(), id.dimmed()),
35+
},
36+
modpack.name.bold(),
37+
)
38+
})
2339
.collect::<Vec<_>>();
2440

2541
let selection = Select::with_theme(&*THEME)
@@ -40,7 +56,7 @@ pub fn delete(config: &mut Config, modpack_name: Option<String>) -> Result<()> {
4056
// And there is more than one modpack
4157
if config.modpacks.len() > 1 {
4258
// Let the user pick which modpack to switch to
43-
switch(config, None)?;
59+
switch(config, switch_to)?;
4460
} else {
4561
config.active_modpack = 0;
4662
}

src/subcommands/profile/delete.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
use super::switch;
22
use crate::THEME;
33
use anyhow::{bail, Result};
4+
use colored::Colorize;
45
use dialoguer::Select;
56
use libium::config::structs::Config;
67

7-
pub fn delete(config: &mut Config, profile_name: Option<String>) -> Result<()> {
8+
pub fn delete(
9+
config: &mut Config,
10+
profile_name: Option<String>,
11+
switch_to: Option<String>,
12+
) -> Result<()> {
813
// If the profile name has been provided as an option
914
let selection = if let Some(profile_name) = profile_name {
1015
match config
@@ -19,7 +24,15 @@ pub fn delete(config: &mut Config, profile_name: Option<String>) -> Result<()> {
1924
let profile_names = config
2025
.profiles
2126
.iter()
22-
.map(|profile| &profile.name)
27+
.map(|profile| {
28+
format!(
29+
"{:6} {:7} {} {}",
30+
format!("{:?}", profile.mod_loader).purple(),
31+
profile.game_version.green(),
32+
profile.name.bold(),
33+
format!("({} mods)", profile.mods.len()).yellow(),
34+
)
35+
})
2336
.collect::<Vec<_>>();
2437

2538
let selection = Select::with_theme(&*THEME)
@@ -40,7 +53,7 @@ pub fn delete(config: &mut Config, profile_name: Option<String>) -> Result<()> {
4053
// And there is more than one profile
4154
if config.profiles.len() > 1 {
4255
// Let the user pick which profile to switch to
43-
switch(config, None)?;
56+
switch(config, switch_to)?;
4457
} else {
4558
config.active_profile = 0;
4659
}

0 commit comments

Comments
 (0)