Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Closes #

### Required

- [ ] cargo check passes
- [ ] cargo fmt --check passes
- [ ] cargo clippy --workspace --all-targets -- -D warnings passes
- [ ] cargo test passes
- [ ] `cargo check` passes
- [ ] `cargo fmt --check` passes
- [ ] `cargo clippy --workspace --all-targets -- -D warnings` passes
- [ ] `cargo test` passes

### Functional Validation

Expand Down
20 changes: 8 additions & 12 deletions apps/dustfril-cli/src/commands/analyze.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dustfril_core::models::{AnalysisResult, CleanupRecommendation};
use dustfril_core::{analyzer, detector};
use dustfril_core::{api, format};

use crate::cli::PathArgs;
use crate::shared::path::{resolve_path, validate_path};
Expand Down Expand Up @@ -37,19 +37,19 @@ fn print_summary(analysis: &AnalysisResult) {

println!(
"Total Size: {}\n",
analyzer::format_size(analysis.total_size_bytes)
format::format_size(analysis.total_size_bytes)
);

println!("Keep: {}", keep);
println!(
"Review: {}, Size: {}",
review,
analyzer::format_size(review_size)
format::format_size(review_size)
);
println!(
"Safe To Clean: {}, Size: {}",
safe_to_clean,
analyzer::format_size(safe_size)
format::format_size(safe_size)
);

println!("\n----------------------------------------\n");
Expand All @@ -62,13 +62,9 @@ pub fn execute(args: PathArgs) {
return;
}

let scan_result = if args.global {
detector::scan_global()
} else {
detector::scan_workspace(&path)
};
let scan_result = api::scan(&path, args.global);

let analysis_result = analyzer::analyze(scan_result);
let analysis_result = api::analyze(scan_result);

if analysis_result.artifacts.is_empty() {
println!("No Rust artifacts found.");
Expand All @@ -82,11 +78,11 @@ pub fn execute(args: PathArgs) {

println!(" Path: {}", artifact.artifact.path.display());

println!(" Size: {}", analyzer::format_size(artifact.size_bytes));
println!(" Size: {}", format::format_size(artifact.size_bytes));

println!(
" Modified: {}",
analyzer::format_modified(artifact.last_modified)
format::format_modified(artifact.last_modified)
);

let age_display = artifact
Expand Down
23 changes: 7 additions & 16 deletions apps/dustfril-cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dustfril_core::{
analyzer, cleaner, detector,
api, format,
models::{CleanupPlan, CleanupResult},
};

Expand All @@ -25,15 +25,9 @@ use std::io::{self, Write};
fn build_cleanup_plan(args: &CleanArgs) -> CleanupPlan {
let path = resolve_path(&args.path_args.path);

let scan_result = if args.path_args.global {
detector::scan_global()
} else {
detector::scan_workspace(&path)
};
let scan_result = api::scan(&path, args.path_args.global);

let analysis = analyzer::analyze(scan_result);

cleaner::create_cleanup_plan(analysis)
api::clean::build_plan(scan_result)
}

fn confirm_cleanup() -> bool {
Expand All @@ -59,15 +53,12 @@ fn print_cleanup_plan(plan: &CleanupPlan) {

println!(" Path: {}", candidate.path.display());

println!(" Size: {}\n", analyzer::format_size(candidate.size_bytes));
println!(" Size: {}\n", format::format_size(candidate.size_bytes));
}

println!("Total Reclaimable Space\n");

println!(
" {}\n",
analyzer::format_size(plan.reclaimable_size_bytes())
);
println!(" {}\n", format::format_size(plan.reclaimable_size_bytes()));
}

fn print_cleanup_result(result: &CleanupResult) {
Expand All @@ -77,7 +68,7 @@ fn print_cleanup_result(result: &CleanupResult) {

println!("Failed: {}", result.failed_paths.len());

println!("Freed: {}", analyzer::format_size(result.freed_size_bytes));
println!("Freed: {}", format::format_size(result.freed_size_bytes));

if !result.deleted_paths.is_empty() {
println!("Deleted\n");
Expand Down Expand Up @@ -105,7 +96,7 @@ pub fn execute(args: &CleanArgs) {
return;
}

let result = cleaner::execute_cleanup(&plan);
let result = api::clean::execute(&plan);

print_cleanup_result(&result);
}
8 changes: 2 additions & 6 deletions apps/dustfril-cli/src/commands/scan.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dustfril_core::detector;
use dustfril_core::api;

use crate::{
cli::PathArgs,
Expand All @@ -12,11 +12,7 @@ pub fn execute(args: PathArgs) {
return;
}

let result = if args.global {
detector::scan_global()
} else {
detector::scan_workspace(&path)
};
let result = api::scan(&path, args.global);

if result.artifacts.is_empty() {
println!("No Rust artifacts found.");
Expand Down
2 changes: 0 additions & 2 deletions crates/dustfril-core/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Analyzer module.
mod age;
mod analyze;
mod format;
mod metadata;
mod recommendation;
mod size;
Expand All @@ -11,7 +10,6 @@ mod tests;

pub use age::calculate_age_days;
pub use analyze::analyze;
pub use format::{format_modified, format_size};
pub use metadata::find_latest_modified;
pub use recommendation::recommend_cleanup;
pub use size::calculate_directory_size;
13 changes: 6 additions & 7 deletions crates/dustfril-core/src/analyzer/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::fs;
use tempfile::TempDir;

use crate::analyzer::{
calculate_age_days, calculate_directory_size, find_latest_modified, format_size,
};
use crate::analyzer::{calculate_age_days, calculate_directory_size, find_latest_modified};
use crate::format::size;
use crate::{
analyzer::analyze,
models::{ArtifactLocation, ArtifactType, ScanResult},
Expand Down Expand Up @@ -64,22 +63,22 @@ fn find_latest_modified_returns_some() {

#[test]
fn format_size_bytes() {
assert_eq!(format_size(512), "512 B");
assert_eq!(size::format_size(512), "512 B");
}

#[test]
fn format_size_kilobytes() {
assert_eq!(format_size(2048), "2.00 KB");
assert_eq!(size::format_size(2048), "2.00 KB");
}

#[test]
fn format_size_megabytes() {
assert_eq!(format_size(1024 * 1024), "1.00 MB");
assert_eq!(size::format_size(1024 * 1024), "1.00 MB");
}

#[test]
fn format_size_gigabytes() {
assert_eq!(format_size(1024 * 1024 * 1024), "1.00 GB");
assert_eq!(size::format_size(1024 * 1024 * 1024), "1.00 GB");
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions crates/dustfril-core/src/api/analyze.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::{analyzer, models::ScanResult};

pub fn analyze(scan_result: ScanResult) -> crate::models::AnalysisResult {
analyzer::analyze(scan_result)
}
13 changes: 13 additions & 0 deletions crates/dustfril-core/src/api/clean.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::{
analyzer, cleaner,
models::{CleanupPlan, CleanupResult, ScanResult},
};

pub fn build_plan(scan: ScanResult) -> CleanupPlan {
let analysis = analyzer::analyze(scan);
cleaner::create_cleanup_plan(analysis)
}

pub fn execute(plan: &CleanupPlan) -> CleanupResult {
cleaner::execute_cleanup(plan)
}
7 changes: 7 additions & 0 deletions crates/dustfril-core/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod analyze;
pub mod clean;
pub mod scan;

pub use analyze::*;
pub use clean::*;
pub use scan::*;
11 changes: 11 additions & 0 deletions crates/dustfril-core/src/api/scan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::path::Path;

use crate::detector;

pub fn scan(root: &Path, global: bool) -> crate::models::ScanResult {
if global {
detector::scan_global()
} else {
detector::scan_workspace(root)
}
}
2 changes: 1 addition & 1 deletion crates/dustfril-core/src/detector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ mod scan;
#[cfg(test)]
mod tests;

pub use scan::{scan, scan_global, scan_project, scan_workspace};
pub use scan::*;
10 changes: 5 additions & 5 deletions crates/dustfril-core/src/detector/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ pub fn scan_global() -> ScanResult {
result
}

pub fn scan(root: &Path) -> ScanResult {
let mut result = scan_workspace(root);
// pub fn scan(root: &Path) -> ScanResult {
// let mut result = scan_workspace(root);

result.artifacts.extend(scan_global().artifacts);
// result.artifacts.extend(scan_global().artifacts);

result
}
// result
// }
12 changes: 12 additions & 0 deletions crates/dustfril-core/src/format/date.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use chrono::{DateTime, Local};
use std::time::SystemTime;

pub fn format_modified(modified: Option<SystemTime>) -> String {
let Some(modified) = modified else {
return "Unknown".to_string();
};

let datetime: DateTime<Local> = modified.into();

datetime.format("%Y-%m-%d %H:%M:%S").to_string()
}
5 changes: 5 additions & 0 deletions crates/dustfril-core/src/format/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod date;
pub mod size;

pub use date::*;
pub use size::*;
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,3 @@ pub fn format_size(bytes: u64) -> String {
format!("{:.0} B", bytes)
}
}

use chrono::{DateTime, Local};
use std::time::SystemTime;

pub fn format_modified(modified: Option<SystemTime>) -> String {
let Some(modified) = modified else {
return "Unknown".to_string();
};

let datetime: DateTime<Local> = modified.into();

datetime.format("%Y-%m-%d %H:%M:%S").to_string()
}
9 changes: 6 additions & 3 deletions crates/dustfril-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
pub mod analyzer;
pub mod cleaner;
pub mod detector;
pub mod api;
pub mod format;
pub mod models;

mod analyzer;
mod cleaner;
mod detector;