Jelajahi Sumber

Adds CHANGELOG and releases v0.1.2

Steve Thielemann 3 minggu lalu
induk
melakukan
1ae230c39c
5 mengubah file dengan 32 tambahan dan 20 penghapusan
  1. 10 0
      CHANGELOG
  2. 1 1
      Cargo.lock
  3. 1 1
      Cargo.toml
  4. 5 1
      README.md
  5. 15 17
      src/main.rs

+ 10 - 0
CHANGELOG

@@ -0,0 +1,10 @@
+v0.1.2 <= Latest + Stable
+    Further enhances nested crates, and expands requirements so 'target/',
+    and 'Cargo.toml' need to be present to run 'cargo clean' (Should help,
+    eliminate running on non-crate projects that might call a directory,
+    'target/')
+v0.1.1
+    Introduced handling nested crates
+v0.1.0
+    Project began as a primative crate that looks in the current directory,
+    looking for 'target/', if found it runs 'cargo clean' automatically

+ 1 - 1
Cargo.lock

@@ -4,4 +4,4 @@ version = 3
 
 [[package]]
 name = "rustpan"
-version = "0.1.1"
+version = "0.1.2"

+ 1 - 1
Cargo.toml

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

+ 5 - 1
README.md

@@ -2,6 +2,8 @@
 
 It's not a dust pan, it's a rust pan. (A cargo cleaner)
 
+> See `CHANGELOG` for info on [v0.1.2](https://git.red-green.com/david/rustpan/src/v0.1.2)
+
 ## Installation
 
 Simple `cargo install --path .`
@@ -10,7 +12,7 @@ Simple `cargo install --path .`
 
 It's a simple rust crate that goes thru the current working directory finding crates (via `target` directory) and calls `cargo clean` to reduce the number of files stored on the file system.
 
-As of [v0.1.1](https://git.red-green.com/david/rustpan/src/v0.1.1) it also supports nested crates...
+As of [v0.1.1](https://git.red-green.com/david/rustpan/src/v0.1.1) it also supports nested crates... (this feature is further enhanced in [v0.1.2](https://git.red-green.com/david/rustpan/src/v0.1.2))
 
 ```
 # E.G.
@@ -27,3 +29,5 @@ dev/rust/major_project/crate3/target/
 ```
 
 The above will be cleaned even if you run rust pan from `dev/rust/` (Or you could run it in `dev/rust/major_project`, which might be better if you only wanted to clean just a handful of crates)
+
+> In [v0.1.2](https://git.red-green.com/david/rustpan/src/v0.1.2), the above can also be cleaned from `dev/`

+ 15 - 17
src/main.rs

@@ -1,14 +1,18 @@
 use std::{fs, path::PathBuf, process, env};
 
 fn find_target_dir(path: PathBuf) -> Result<bool, std::io::Error> {
+    let mut found_target_dir: bool = false;
+    let mut found_cargo_toml: bool = false;
     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);
+            found_target_dir = true;
+        } else if p.is_file() && p.file_name().unwrap() == "Cargo.toml" {
+            found_cargo_toml = true;
         }
     }
-    Ok(false)
+    Ok(found_target_dir && found_cargo_toml)
 }
 
 fn execute_clean(path: PathBuf) -> Result<(), std::io::Error> {
@@ -32,18 +36,8 @@ fn clean_in_dir(path: PathBuf) -> Result<u64, std::io::Error> {
                 cleaned += 1;
             } else {
                 // Maybe nested?
-                for ent in fs::read_dir(p)? {
-                    let ent = ent?;
-                    let p2 = ent.path();
-                    if p2.is_dir() {
-                        let needed = find_target_dir(p2.clone())?;
-                        if needed {
-                            println!(" => {}", p2.display());
-                            execute_clean(p2)?;
-                            cleaned += 1;
-                        }
-                    }
-                }
+                let r = clean_in_dir(p)?;
+                cleaned += r;
             }
         }
     }
@@ -51,9 +45,13 @@ fn clean_in_dir(path: PathBuf) -> Result<u64, std::io::Error> {
 }
 
 fn main() -> Result<(), std::io::Error> {
-    println!("Rust Pan");
+    println!("Sweeping...");
     let cwd = env::current_dir()?;
-    let cleand = clean_in_dir(cwd)?;
-    println!("Cleaned {} crates", cleand);
+    let cleaned = clean_in_dir(cwd)?;
+    if cleaned == 1 {
+        println!("Cleaned 1 crate");
+    } else {
+        println!("Cleaned {} crates", cleaned);
+    }
     Ok(())
 }