Przeglądaj źródła

Release v0.1.0

  Tired of cleaning crates manually? Don't manually, use Rustpan!

Assuming you store you're rust project's like so...

dev/
    rust/
         crate1/
                src/
                target/ <= We know if target exists, 'cargo clean'
         crate2/
                src/
                <= If target doesn't exist, continue
         major_project/
                       sub_crate1/
                                  src/
                                  target/
                       sub_crate2/
                                  src/
                                  target/

The above will be cleaned:

dev/rust/crate1
dev/rust/major_project/sub_crate1
dev/rust/major_project/sub_crate2
Apollo 3 tygodni temu
rodzic
commit
46b88aa2e9
4 zmienionych plików z 59 dodań i 0 usunięć
  1. 1 0
      .gitignore
  2. 7 0
      Cargo.lock
  3. 6 0
      Cargo.toml
  4. 45 0
      src/main.rs

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/target

+ 7 - 0
Cargo.lock

@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "rustpan"
+version = "0.1.0"

+ 6 - 0
Cargo.toml

@@ -0,0 +1,6 @@
+[package]
+name = "rustpan"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]

+ 45 - 0
src/main.rs

@@ -0,0 +1,45 @@
+use std::{fs, path::PathBuf, process, env};
+
+fn find_target_dir(path: PathBuf) -> Result<bool, std::io::Error> {
+    for entry in fs::read_dir(path)? {
+        let entry = entry?;
+        let p = entry.path();
+        if p.is_dir() && p.ends_with("target") {
+            return Ok(true);
+        }
+    }
+    Ok(false)
+}
+
+fn execute_clean(path: PathBuf) -> Result<(), std::io::Error> {
+    let _cmd = process::Command::new("cargo")
+        .current_dir(path)
+        .arg("clean")
+        .status()?;
+    Ok(())
+}
+
+fn clean_in_dir(path: PathBuf) -> Result<u64, std::io::Error> {
+    let mut cleaned: u64 = 0;
+    for entry in fs::read_dir(path)? {
+        let entry = entry?;
+        let p = entry.path();
+        if p.is_dir() {
+            let needed = find_target_dir(p.clone())?;
+            if needed {
+                println!(" => {}", p.display());
+                execute_clean(p)?;
+                cleaned += 1;
+            }
+        }
+    }
+    Ok(cleaned)
+}
+
+fn main() -> Result<(), std::io::Error> {
+    println!("Rust Pan");
+    let cwd = env::current_dir()?;
+    let cleand = clean_in_dir(cwd)?;
+    println!("Cleaned {} crates", cleand);
+    Ok(())
+}