use anyhow::anyhow;
use super::*;
#[derive(Parser, Debug)]
pub struct LeoClean {}
impl Command for LeoClean {
type Input = ();
type Output = ();
fn log_span(&self) -> Span {
tracing::span!(tracing::Level::INFO, "Leo")
}
fn prelude(&self, _: Context) -> Result<Self::Input> {
Ok(())
}
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
let path = context.dir()?;
let manifest_path = path.join(leo_package::MANIFEST_FILENAME);
if !manifest_path.exists() {
return Err(anyhow!(
"{} doesn't exist - this doesn't appear to be a Leo package.",
leo_package::MANIFEST_FILENAME
)
.into());
}
let outputs_path = path.join(leo_package::OUTPUTS_DIRECTORY);
if std::fs::remove_dir_all(&outputs_path).is_ok() {
tracing::info!("🧹 Cleaned the outputs directory {}", outputs_path.display().to_string().dimmed());
}
let build_path = path.join(leo_package::BUILD_DIRECTORY);
if std::fs::remove_dir_all(&build_path).is_ok() {
tracing::info!("🧹 Cleaned the build directory {}", build_path.display().to_string().dimmed());
}
Ok(())
}
}