From 4fe35b4b603a84657aa8f811d398f1baf2797b5f Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Wed, 1 Sep 2021 16:25:18 +0200 Subject: [PATCH] add clean command --- mpt/src/commands/clean.rs | 24 ++++++++++++++++++++++++ mpt/src/commands/mod.rs | 1 + mpt/src/main.rs | 10 ++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 mpt/src/commands/clean.rs diff --git a/mpt/src/commands/clean.rs b/mpt/src/commands/clean.rs new file mode 100644 index 0000000..e124c40 --- /dev/null +++ b/mpt/src/commands/clean.rs @@ -0,0 +1,24 @@ +use crate::{config::Config, util::CliStyle}; + +pub async fn run(config: Config) -> anyhow::Result<()> { + // These operations are so incredibly performance-critical that we absolutely + // must execute them in parallel! + let (res1, res2) = tokio::join!( + async { + println!( + "{}", + format!("Deleting {}", config.locations.temp_dir.to_string_lossy()).info(), + ); + tokio::fs::remove_dir_all(config.locations.temp_dir).await + }, + async { + println!("{}", "Deleting build".info(),); + tokio::fs::remove_dir_all("build").await + } + ); + + res1?; + res2?; + + Ok(()) +} diff --git a/mpt/src/commands/mod.rs b/mpt/src/commands/mod.rs index a9917b5..3d5d913 100644 --- a/mpt/src/commands/mod.rs +++ b/mpt/src/commands/mod.rs @@ -1,3 +1,4 @@ pub mod buildtwitch; +pub mod clean; pub mod downloadmods; pub mod init; diff --git a/mpt/src/main.rs b/mpt/src/main.rs index 121244e..a9b874f 100644 --- a/mpt/src/main.rs +++ b/mpt/src/main.rs @@ -15,6 +15,7 @@ struct Opt { #[derive(StructOpt)] enum Command { + #[structopt(help = "Initializes a new modpack")] Init { #[structopt(help = "The name of the modpack")] modpack_name: String, @@ -24,7 +25,7 @@ enum Command { mcversion: String, }, - #[structopt(name = "downloadmods")] + #[structopt(name = "downloadmods", help = "Downloads mods of the pack")] DownloadMods { #[structopt(help = "Directory to download mods to")] dir: PathBuf, @@ -32,7 +33,7 @@ enum Command { all: bool, }, - #[structopt(name = "buildtwitch")] + #[structopt(name = "buildtwitch", help = "Builds a twitch export of the pack")] BuildTwitch { #[structopt( short, @@ -41,6 +42,9 @@ enum Command { )] all: bool, }, + + #[structopt(help = "Deletes artifacts and temporary files")] + Clean, } #[tokio::main] @@ -61,6 +65,8 @@ async fn main() -> anyhow::Result<()> { Command::BuildTwitch { all } => { commands::buildtwitch::run(util::parse_config_and_manifest().await?, all).await? }, + + Command::Clean => commands::clean::run(util::parse_config().await?).await?, } Ok(())