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
47 changes: 47 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 34 additions & 2 deletions apps/dustfril-cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use clap::{Args, Parser, Subcommand};
use dustfril_core::models::Ecosystem;

/// DustFril CLI
#[derive(Parser)]
Expand All @@ -27,9 +28,34 @@ pub enum Commands {
pub struct PathArgs {
pub path: Option<PathBuf>,

/// Scan the entire system instead of a specific workspace.
#[arg(long)]
pub global: bool,
pub rust: bool,

#[arg(long)]
pub node: bool,

#[arg(long)]
pub java: bool,
}

impl PathArgs {
pub fn ecosystems(&self) -> Vec<Ecosystem> {
let mut ecosystems = Vec::new();

if self.rust {
ecosystems.push(Ecosystem::Rust);
}

if self.node {
ecosystems.push(Ecosystem::Node);
}

if self.java {
ecosystems.push(Ecosystem::Java);
}

ecosystems
}
}

#[derive(Args)]
Expand All @@ -41,3 +67,9 @@ pub struct CleanArgs {
#[arg(long)]
pub dry_run: bool,
}

impl CleanArgs {
pub fn ecosystems(&self) -> Vec<Ecosystem> {
self.path_args.ecosystems()
}
}
32 changes: 17 additions & 15 deletions apps/dustfril-cli/src/commands/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn print_summary(analysis: &AnalysisResult) {
keep += 1;
}

CleanupRecommendation::Review => {
CleanupRecommendation::NeedsReview => {
review += 1;
review_size += artifact.size_bytes;
}
Expand Down Expand Up @@ -64,7 +64,9 @@ pub fn execute(args: PathArgs) {
return;
}

let scan_result = match api::scan(&path, args.global) {
let ecosystems = args.ecosystems();

let scan_result = match api::scan(&path, &ecosystems) {
Ok(res) => res,
Err(e) => {
eprintln!("Scan failed: {}", e);
Expand All @@ -81,30 +83,30 @@ pub fn execute(args: PathArgs) {
};

if analysis_result.artifacts.is_empty() {
println!("No Rust artifacts found.");
println!("No artifacts found.");
return;
}

println!("Found {} artifact(s)\n", analysis_result.artifacts.len());

for artifact in &analysis_result.artifacts {
println!("[{}]", artifact.artifact.artifact_type);
println!(" Path: {}", artifact.artifact.path.display());
println!(" Size: {}", format::format_size(artifact.size_bytes));

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

let age_display = artifact
.age_days
.map(|d| format!("{d} days"))
.unwrap_or_else(|| "Unknown".to_string());

println!(" Age: {}", age_display);

println!(" Recommendation: {}\n", artifact.recommendation);
println!("[{}]", artifact.artifact.ecosystem);
println!(" Path: {}", artifact.artifact.path.display());
println!(
" Size: {}",
format::format_size(artifact.size_bytes)
);
println!(
" Modified: {}",
format::format_modified(artifact.last_modified)
);
println!(" Age: {}", age_display);
println!(" Recommendation: {}", artifact.recommendation);
}

print_summary(&analysis_result);
Expand Down
105 changes: 61 additions & 44 deletions apps/dustfril-cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
use std::io::{self, Write};

use dustfril_core::{
api,
error::DustError,
models::{CleanupPlan, CleanupResult},
};

use crate::{cli::CleanArgs, format, shared::path::resolve_path};
use crate::{
cli::CleanArgs,
format,
shared::path::{resolve_path, validate_path},
};

pub fn dry_run(args: &CleanArgs) {
let plan = match build_cleanup_plan(args) {
Ok(plan) => plan,
Err(e) => {
eprintln!("Scan failed: {}", e);
eprintln!("Cleanup preview failed: {}", e);
return;
}
};
Expand All @@ -24,20 +30,56 @@ pub fn dry_run(args: &CleanArgs) {
println!("No files were deleted.");
}

use std::io::{self, Write};
pub fn execute(args: &CleanArgs) {
let plan = match build_cleanup_plan(args) {
Ok(plan) => plan,
Err(e) => {
eprintln!("Cleanup preparation failed: {}", e);
return;
}
};

if plan.candidates.is_empty() {
println!("No cleanup candidates found.");
return;
}

print_cleanup_plan(&plan);

if !confirm_cleanup() {
println!("Cleanup cancelled.");
return;
}

let result = match api::clean::execute(&plan) {
Ok(res) => res,
Err(e) => {
eprintln!("Cleanup failed: {}", e);
return;
}
};

print_cleanup_result(&result);
}

fn build_cleanup_plan(args: &CleanArgs) -> Result<CleanupPlan, DustError> {
let path = resolve_path(&args.path_args.path);

let scan = api::scan(&path, args.path_args.global)?;
if !validate_path(&path) {
return Err(DustError::InvalidPath(path));
}

let ecosystems = args.ecosystems();

let scan = api::scan(&path, &ecosystems)?;
let plan = api::clean::build_plan(scan)?;

Ok(plan)
}

fn confirm_cleanup() -> bool {
print!("Continue? (y/N): ");

// Flush stdout to ensure the prompt is displayed before reading input
io::stdout().flush().expect("Failed to flush stdout");

let mut input = String::new();
Expand All @@ -53,65 +95,40 @@ fn print_cleanup_plan(plan: &CleanupPlan) {
println!("Cleanup Preview\n");

for candidate in &plan.candidates {
println!("[{}]", candidate.artifact_type);

println!("[{}]", candidate.ecosystem);
println!(" Path: {}", candidate.path.display());
println!(" Size: {}", format::format_size(candidate.size_bytes));

println!(" Size: {}\n", format::format_size(candidate.size_bytes));
}
if let Some(age_days) = candidate.age_days {
println!(" Age: {} day(s)", age_days);
}

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

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

fn print_cleanup_result(result: &CleanupResult) {
println!("Cleanup completed.");

println!("Deleted: {}", result.deleted_paths.len());

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

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

if !result.deleted_paths.is_empty() {
println!("Deleted\n");
println!("\nDeleted");

for path in &result.deleted_paths {
println!(" {}", path.display());
}

println!();
}
}
pub fn execute(args: &CleanArgs) {
let plan = match build_cleanup_plan(args) {
Ok(plan) => plan,
Err(e) => {
eprintln!("Scan failed: {}", e);
return;
}
};

if plan.candidates.is_empty() {
println!("No cleanup candidates found.");
return;
}

print_cleanup_plan(&plan);

if !confirm_cleanup() {
println!("Cleanup cancelled.");
return;
}
if !result.failed_paths.is_empty() {
println!("\nFailed");

let result = match api::clean::execute(&plan) {
Ok(res) => res,
Err(e) => {
eprintln!("Cleanup failed: {}", e);
return;
for path in &result.failed_paths {
println!(" {}", path.display());
}
};

print_cleanup_result(&result);
}
}
10 changes: 5 additions & 5 deletions apps/dustfril-cli/src/commands/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ pub fn execute(args: PathArgs) {
return;
}

let result = match api::scan(&path, args.global) {
let ecosystems = args.ecosystems();

let result = match api::scan(&path, &ecosystems) {
Ok(res) => res,
Err(e) => {
eprintln!("Scan failed: {}", e);
Expand All @@ -22,15 +24,13 @@ pub fn execute(args: PathArgs) {
};

if result.artifacts.is_empty() {
println!("No Rust artifacts found.");
println!("No artifacts found.");
return;
}

println!("Found {} artifact(s)\n", result.artifacts.len());

for artifact in result.artifacts {
println!("[{}]", artifact.artifact_type);

println!(" {}\n", artifact.path.display());
println!(" {:?}\n", artifact.path);
Comment on lines 31 to +34

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Show the ecosystem in scan output.

Lines 31-34 print only artifact.path via {:?}, which drops the new ecosystem information and makes the user-facing output harder to read.

Suggested fix
-    for artifact in result.artifacts {
-        println!("  {:?}\n", artifact.path);
+    for artifact in result.artifacts {
+        println!("  [{}] {}", artifact.ecosystem, artifact.path.display());
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
println!("Found {} artifact(s)\n", result.artifacts.len());
for artifact in result.artifacts {
println!("[{}]", artifact.artifact_type);
println!(" {}\n", artifact.path.display());
println!(" {:?}\n", artifact.path);
println!("Found {} artifact(s)\n", result.artifacts.len());
for artifact in result.artifacts {
println!(" [{}] {}", artifact.ecosystem, artifact.path.display());
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/dustfril-cli/src/commands/scan.rs` around lines 31 - 34, The scan
command output currently prints only each artifact’s path, so the new ecosystem
information is lost. Update the user-facing printing in the scan flow in the
`scan` command so it includes the artifact ecosystem alongside the path, using
the existing `result.artifacts` iteration and `artifact` fields. Make the output
more readable by formatting both values together instead of only using
`artifact.path`.

}
}
2 changes: 2 additions & 0 deletions crates/dustfril-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ version = "0.1.0"
edition = "2024"

[dependencies]
rayon = "1.12.0"
serde = { version = "1", features = ["derive"] }
walkdir = "2.5.0"

[dev-dependencies]
tempfile = "3.0"
Loading
Loading