forc 0.32.0

Fuel Orchestrator.
Documentation
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;

    // find manifest directory, even if in subdirectory
    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(),
            )
        }
    };

    // Clear `<project>/out` directory.
    // Ignore I/O errors telling us `out_dir` isn't there.
    let out_dir = default_output_directory(&manifest_dir);
    let _ = std::fs::remove_dir_all(out_dir);

    Ok(())
}