-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from Ackee-Blockchain/feat/clean_command
Feat/clean command
- Loading branch information
Showing
6 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,6 @@ pub use explorer::{explorer, ExplorerCommand}; | |
|
||
mod init; | ||
pub use init::init; | ||
|
||
mod clean; | ||
pub use clean::clean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use anyhow::Error; | ||
use fehler::throws; | ||
use trdelnik_client::Cleaner; | ||
|
||
#[throws] | ||
pub async fn clean() { | ||
let cleaner = Cleaner::new(); | ||
cleaner.clean_target().await?; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::config::Config; | ||
use fehler::{throw, throws}; | ||
use std::{ | ||
io, | ||
path::{Path, PathBuf}, | ||
}; | ||
use thiserror::Error; | ||
use tokio::{fs, process::Command}; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum Error { | ||
#[error("{0:?}")] | ||
Io(#[from] io::Error), | ||
#[error("Cannot find the Anchor.toml file to locate the root folder")] | ||
BadWorkspace, | ||
} | ||
|
||
pub struct Cleaner; | ||
|
||
impl Default for Cleaner { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl Cleaner { | ||
pub fn new() -> Self { | ||
Self | ||
} | ||
#[throws] | ||
pub async fn clean_target(&self) { | ||
let root = match Config::discover_root() { | ||
Ok(root) => root, | ||
Err(_) => throw!(Error::BadWorkspace), | ||
}; | ||
self.clean_anchor_target().await?; | ||
self.clean_hfuzz_target(&root).await?; | ||
} | ||
|
||
#[throws] | ||
async fn clean_anchor_target(&self) { | ||
Command::new("anchor").arg("clean").spawn()?.wait().await?; | ||
} | ||
#[throws] | ||
async fn clean_hfuzz_target(&self, root: &PathBuf) { | ||
let hfuzz_target_path = Path::new(root) | ||
.join(crate::test_generator::TESTS_WORKSPACE) | ||
.join(crate::test_generator::HFUZZ_TARGET); | ||
if hfuzz_target_path.exists() { | ||
fs::remove_dir_all(hfuzz_target_path).await?; | ||
} else { | ||
println!( | ||
"skipping {}/{} directory: not found", | ||
crate::test_generator::TESTS_WORKSPACE, | ||
crate::test_generator::HFUZZ_TARGET | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters