mz_deploy/cli/commands/
clean.rs1use crate::cli::CliError;
13use crate::config::Settings;
14use crate::log;
15use crate::types::BUILD_DIR;
16use std::fmt;
17use std::path::PathBuf;
18
19#[derive(serde::Serialize)]
20struct CleanResult {
21 path: PathBuf,
22 removed: bool,
23}
24
25impl fmt::Display for CleanResult {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 if self.removed {
28 write!(f, " \u{2713} Removed {}", self.path.display())
29 } else {
30 write!(
31 f,
32 " \u{2713} Nothing to clean ({} not present)",
33 self.path.display()
34 )
35 }
36 }
37}
38
39pub fn run(settings: &Settings) -> Result<(), CliError> {
44 let target = settings.directory.join(BUILD_DIR);
45 let removed = match std::fs::remove_dir_all(&target) {
46 Ok(()) => true,
47 Err(e) if e.kind() == std::io::ErrorKind::NotFound => false,
48 Err(e) => return Err(CliError::Io(e)),
49 };
50 log::output(&CleanResult {
51 path: target,
52 removed,
53 });
54 Ok(())
55}