use crate::cli::CleanCommand;
use anyhow::{anyhow, bail, Result};
use forc_util::{default_output_directory, find_manifest_dir};
use std::path::PathBuf;
use sway_utils::MANIFEST_FILE_NAME;
pub fn clean(command: CleanCommand) -> Result<()> {
let CleanCommand { path } = command;
let this_dir = if let Some(ref path) = path {
PathBuf::from(path)
} else {
std::env::current_dir().map_err(|e| anyhow!("{:?}", e))?
};
let manifest_dir = match find_manifest_dir(&this_dir) {
Some(dir) => dir,
None => {
bail!(
"could not find `{}` in `{}` or any parent directory",
MANIFEST_FILE_NAME,
this_dir.display(),
)
}
};
let out_dir = default_output_directory(&manifest_dir);
let _ = std::fs::remove_dir_all(out_dir);
Ok(())
}