leo_lang/cli/commands/
clean.rs

1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17use super::*;
18
19/// Clean outputs folder command
20#[derive(Parser, Debug)]
21pub struct LeoClean {}
22
23impl Command for LeoClean {
24    type Input = ();
25    type Output = ();
26
27    fn log_span(&self) -> Span {
28        tracing::span!(tracing::Level::INFO, "Leo")
29    }
30
31    fn prelude(&self, _: Context) -> Result<Self::Input> {
32        Ok(())
33    }
34
35    fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
36        let path = context.dir()?;
37
38        // Removes the outputs/ directory.
39        let outputs_path = path.join(leo_package::OUTPUTS_DIRECTORY);
40        std::fs::remove_dir_all(&outputs_path)
41            .map_err(|e| PackageError::failed_to_remove_directory(outputs_path.display(), e))?;
42        tracing::info!("🧹 Cleaned the outputs directory {}", outputs_path.display().to_string().dimmed());
43
44        // Removes the build/ directory.
45        let build_path = path.join(leo_package::BUILD_DIRECTORY);
46        std::fs::remove_dir_all(&build_path)
47            .map_err(|e| PackageError::failed_to_remove_directory(build_path.display(), e))?;
48        tracing::info!("🧹 Cleaned the build directory {}", build_path.display().to_string().dimmed());
49
50        Ok(())
51    }
52}