mirror of
https://github.com/WarrenHood/MCModpackManager.git
synced 2025-04-29 18:44:58 +01:00
Added option to forcefully remove a mod
This commit is contained in:
parent
a2c50b743a
commit
e0b1b5bcb1
12
src/main.rs
12
src/main.rs
|
@ -74,6 +74,9 @@ enum Commands {
|
|||
Remove {
|
||||
/// Name of the mod to remove from the modpack
|
||||
name: String,
|
||||
/// Forcefully remove the mod without checking if anything depends on it
|
||||
#[arg(long, short, action)]
|
||||
force: bool,
|
||||
},
|
||||
/// Download the mods in the pack to a specified folder
|
||||
Download {
|
||||
|
@ -87,7 +90,7 @@ enum Commands {
|
|||
/// Use exact transitive mod dependency versions
|
||||
#[arg(long, short, action)]
|
||||
locked: bool,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "multi_thread")]
|
||||
|
@ -194,7 +197,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
match resolver::PinnedPackMeta::load_from_current_directory(!locked).await {
|
||||
Ok(mut modpack_lock) => {
|
||||
let remove_result = modpack_lock.remove_mod(&mod_meta.name, &modpack_meta);
|
||||
let remove_result =
|
||||
modpack_lock.remove_mod(&mod_meta.name, &modpack_meta, true);
|
||||
if let Err(e) = remove_result {
|
||||
revert_modpack_meta(e);
|
||||
}
|
||||
|
@ -215,7 +219,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
}
|
||||
};
|
||||
}
|
||||
Commands::Remove { name } => {
|
||||
Commands::Remove { name, force } => {
|
||||
let mut modpack_meta = ModpackMeta::load_from_current_directory()?;
|
||||
let old_modpack_meta = modpack_meta.clone();
|
||||
|
||||
|
@ -232,7 +236,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
match resolver::PinnedPackMeta::load_from_current_directory(true).await {
|
||||
Ok(mut modpack_lock) => {
|
||||
let remove_result = modpack_lock.remove_mod(&name, &modpack_meta);
|
||||
let remove_result = modpack_lock.remove_mod(&name, &modpack_meta, force);
|
||||
if let Err(e) = remove_result {
|
||||
revert_modpack_meta(e);
|
||||
}
|
||||
|
|
|
@ -259,15 +259,20 @@ impl PinnedPackMeta {
|
|||
&mut self,
|
||||
mod_name: &str,
|
||||
pack_metadata: &ModpackMeta,
|
||||
force: bool,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let dependent_mods = self.get_dependent_mods(mod_name);
|
||||
|
||||
if dependent_mods.len() > 0 {
|
||||
return Err(format!(
|
||||
"Cannot remove mod {}.The following mods depend on it:\n{:#?}",
|
||||
mod_name, dependent_mods
|
||||
)
|
||||
.into());
|
||||
if force {
|
||||
println!("Forcefully removing mod {} even though it is depended on by the following mods:\n{:#?}", mod_name, dependent_mods);
|
||||
} else {
|
||||
return Err(format!(
|
||||
"Cannot remove mod {}.The following mods depend on it:\n{:#?}",
|
||||
mod_name, dependent_mods
|
||||
)
|
||||
.into());
|
||||
}
|
||||
}
|
||||
let removed_mod = self.mods.remove(mod_name);
|
||||
if let Some(removed_mod) = removed_mod {
|
||||
|
|
Loading…
Reference in a new issue