Browse Source

cli: Make `clean` command also remove the `.anchor` directory (#3192)

acheron 1 year ago
parent
commit
d732e756e1
1 changed files with 7 additions and 1 deletions
  1. 7 1
      cli/src/lib.rs

+ 7 - 1
cli/src/lib.rs

@@ -249,7 +249,7 @@ pub enum Command {
         #[clap(subcommand)]
         #[clap(subcommand)]
         subcmd: IdlCommand,
         subcmd: IdlCommand,
     },
     },
-    /// Remove all artifacts from the target directory except program keypairs.
+    /// Remove all artifacts from the generated directories except program keypairs.
     Clean,
     Clean,
     /// Deploys each program in the workspace.
     /// Deploys each program in the workspace.
     Deploy {
     Deploy {
@@ -3733,9 +3733,15 @@ fn cluster_url(cfg: &Config, test_validator: &Option<TestValidator>) -> String {
 fn clean(cfg_override: &ConfigOverride) -> Result<()> {
 fn clean(cfg_override: &ConfigOverride) -> Result<()> {
     let cfg = Config::discover(cfg_override)?.expect("Not in workspace.");
     let cfg = Config::discover(cfg_override)?.expect("Not in workspace.");
     let cfg_parent = cfg.path().parent().expect("Invalid Anchor.toml");
     let cfg_parent = cfg.path().parent().expect("Invalid Anchor.toml");
+    let dot_anchor_dir = cfg_parent.join(".anchor");
     let target_dir = cfg_parent.join("target");
     let target_dir = cfg_parent.join("target");
     let deploy_dir = target_dir.join("deploy");
     let deploy_dir = target_dir.join("deploy");
 
 
+    if dot_anchor_dir.exists() {
+        fs::remove_dir_all(&dot_anchor_dir)
+            .map_err(|e| anyhow!("Could not remove directory {:?}: {}", dot_anchor_dir, e))?;
+    }
+
     if target_dir.exists() {
     if target_dir.exists() {
         for entry in fs::read_dir(target_dir)? {
         for entry in fs::read_dir(target_dir)? {
             let path = entry?.path();
             let path = entry?.path();