|
@@ -7,9 +7,6 @@ const SECS_IN_DAY: u64 = 86400;
|
|
|
#[derive(Parser, Debug)]
|
|
|
#[command(version, about = "It's not a dust pan, it's a rust pan. (A cargo cleaner)", long_about = None)]
|
|
|
struct Args {
|
|
|
- #[arg(short='v', long="verbose")]
|
|
|
- /// Print extra information
|
|
|
- verbose: bool,
|
|
|
#[arg(short='d', long="days", default_value_t=30)]
|
|
|
/// Days since last modified and/or last accessed
|
|
|
days: u32,
|
|
@@ -72,7 +69,7 @@ fn execute_clean(path: PathBuf) -> anyResult<()> {
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
-fn clean_in_dir(path: PathBuf, verbose: bool, forced: bool, days: u64) -> anyResult<u64> {
|
|
|
+fn clean_in_dir(path: PathBuf, forced: bool, days: u64) -> anyResult<u64> {
|
|
|
let mut cleaned: u64 = 0;
|
|
|
for entry in fs::read_dir(path)? {
|
|
|
let entry = entry?;
|
|
@@ -94,22 +91,16 @@ fn clean_in_dir(path: PathBuf, verbose: bool, forced: bool, days: u64) -> anyRes
|
|
|
}
|
|
|
let d = el / SECS_IN_DAY;
|
|
|
if d < days {
|
|
|
- if verbose {
|
|
|
- println!(" => {} (dirty, {} days)", p.display(), d);
|
|
|
- }
|
|
|
+ println!(" => {} (dirty, {} days)", p.display(), d);
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- if !verbose {
|
|
|
- println!(" => {}", p.display());
|
|
|
- } else {
|
|
|
- println!(" => {} (dirty)", p.display());
|
|
|
- }
|
|
|
+ println!(" => {} (dirty)", p.display());
|
|
|
execute_clean(p)?;
|
|
|
cleaned += 1;
|
|
|
} else {
|
|
|
// Maybe nested?
|
|
|
- let r = clean_in_dir(p, verbose, forced, days)?;
|
|
|
+ let r = clean_in_dir(p, forced, days)?;
|
|
|
cleaned += r;
|
|
|
}
|
|
|
}
|
|
@@ -118,10 +109,15 @@ fn clean_in_dir(path: PathBuf, verbose: bool, forced: bool, days: u64) -> anyRes
|
|
|
}
|
|
|
|
|
|
fn main() -> anyResult<()> {
|
|
|
- let cli = Args::parse();
|
|
|
+ let mut cli = Args::parse();
|
|
|
+ if cli.days == 0 {
|
|
|
+ println!("0 days, using --force instead");
|
|
|
+ cli.force = true;
|
|
|
+ cli.days = 30;
|
|
|
+ }
|
|
|
println!("Sweeping...");
|
|
|
let cwd = env::current_dir()?;
|
|
|
- let cleaned = clean_in_dir(cwd, cli.verbose, cli.force, cli.days as u64)?;
|
|
|
+ let cleaned = clean_in_dir(cwd, cli.force, cli.days as u64)?;
|
|
|
if cleaned == 1 {
|
|
|
println!("Cleaned 1 crate");
|
|
|
} else {
|