-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zk_toolbox): Clean command (#2387)
## What ❔ <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. --------- Signed-off-by: Danil <[email protected]>
- Loading branch information
1 parent
275a333
commit 52a4680
Showing
4 changed files
with
91 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use anyhow::Context; | ||
use clap::Subcommand; | ||
use common::{docker, logger}; | ||
use config::{EcosystemConfig, DOCKER_COMPOSE_FILE}; | ||
use xshell::Shell; | ||
|
||
use crate::messages::{ | ||
MSG_CONTRACTS_CLEANING, MSG_CONTRACTS_CLEANING_FINISHED, MSG_DOCKER_COMPOSE_CLEANED, | ||
MSG_DOCKER_COMPOSE_DOWN, MSG_DOCKER_COMPOSE_REMOVE_VOLUMES, | ||
}; | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub enum CleanCommands { | ||
All, | ||
Containers, | ||
ContractsCache, | ||
} | ||
|
||
pub fn run(shell: &Shell, args: CleanCommands) -> anyhow::Result<()> { | ||
let ecosystem = EcosystemConfig::from_file(shell)?; | ||
match args { | ||
CleanCommands::All => { | ||
containers(shell)?; | ||
contracts(shell, &ecosystem)?; | ||
} | ||
CleanCommands::Containers => containers(shell)?, | ||
CleanCommands::ContractsCache => contracts(shell, &ecosystem)?, | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn containers(shell: &Shell) -> anyhow::Result<()> { | ||
logger::info(MSG_DOCKER_COMPOSE_DOWN); | ||
docker::down(shell, DOCKER_COMPOSE_FILE)?; | ||
logger::info(MSG_DOCKER_COMPOSE_REMOVE_VOLUMES); | ||
shell.remove_path("volumes")?; | ||
logger::info(MSG_DOCKER_COMPOSE_CLEANED); | ||
Ok(()) | ||
} | ||
|
||
pub fn contracts(shell: &Shell, ecosystem_config: &EcosystemConfig) -> anyhow::Result<()> { | ||
let path_to_foundry = ecosystem_config.path_to_foundry(); | ||
logger::info(MSG_CONTRACTS_CLEANING); | ||
shell | ||
.remove_path(path_to_foundry.join("artifacts")) | ||
.context("artifacts")?; | ||
shell | ||
.remove_path(path_to_foundry.join("cache")) | ||
.context("cache")?; | ||
shell | ||
.remove_path(path_to_foundry.join("cache-forge")) | ||
.context("cache-forge")?; | ||
shell | ||
.remove_path(path_to_foundry.join("out")) | ||
.context("out")?; | ||
shell | ||
.remove_path(path_to_foundry.join("typechain")) | ||
.context("typechain")?; | ||
shell | ||
.remove_path(path_to_foundry.join("script-config")) | ||
.context("remove script-config")?; | ||
shell | ||
.create_dir(path_to_foundry.join("script-config")) | ||
.context("create script-config")?; | ||
shell | ||
.remove_path(path_to_foundry.join("script-out")) | ||
.context("remove script-out")?; | ||
shell | ||
.create_dir(path_to_foundry.join("script-out")) | ||
.context("create script-out")?; | ||
logger::info(MSG_CONTRACTS_CLEANING_FINISHED); | ||
Ok(()) | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod clean; | ||
pub mod database; | ||
pub mod test; |
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