add clean command

This commit is contained in:
LordMZTE 2021-09-01 16:25:18 +02:00
parent 8939d1195d
commit 4fe35b4b60
3 changed files with 33 additions and 2 deletions

24
mpt/src/commands/clean.rs Normal file
View file

@ -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(())
}

View file

@ -1,3 +1,4 @@
pub mod buildtwitch;
pub mod clean;
pub mod downloadmods;
pub mod init;

View file

@ -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(())