Skip to content

Commit e61bf2a

Browse files
committed
Calculate sizes for artifacts, use progress bar in main
1 parent 8cce13b commit e61bf2a

5 files changed

Lines changed: 194 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 155 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ edition = "2024"
66
[dependencies]
77
clap = { version = "4.4", features = ["derive"] }
88
console = "0.15"
9+
dialoguer = "0.11.0"
910
globset = "0.4"
11+
indicatif = "0.17.11"
1012
walkdir = "2.4"
1113

1214
[dev-dependencies]
13-
assert_fs = "1"
15+
assert_fs = "1"

src/crufty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pub mod cli;
22
pub mod estimator;
33
pub mod fetcher;
44
pub mod types;
5+
pub mod ui;

src/crufty/ui.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use indicatif::{ProgressBar, ProgressStyle};
2+
3+
/// Creates and returns a configured progress bar for use in the application.
4+
pub fn create_progress_bar(total: u64) -> ProgressBar {
5+
let pb = ProgressBar::new(total);
6+
let template =
7+
"{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} {msg}";
8+
let style = ProgressStyle::default_bar()
9+
.template(template)
10+
.unwrap()
11+
.progress_chars("#>-");
12+
pb.set_style(style);
13+
pb
14+
}

src/main.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use clap::Parser;
22
use console::{style, Term};
33
use crufty::cli::{Cli, Commands};
4+
use crufty::estimator::estimate;
45
use crufty::fetcher::fetch_artifacts;
56
use crufty::types::Size;
7+
use crufty::ui;
68
use std::env;
79
use std::io;
810
use std::process;
@@ -26,16 +28,26 @@ fn scan() -> io::Result<()> {
2628
term
2729
.write_line(&format!("[+] Scanning: {}", style(path.display()).bold()))?;
2830
term.write_line("")?;
29-
let artifacts = fetch_artifacts(&path);
31+
32+
// Fetch artifacts
33+
let mut artifacts = fetch_artifacts(&path);
3034

3135
if artifacts.is_empty() {
3236
term.write_line("No significant build artifacts found.")
3337
} else {
38+
let pb = ui::create_progress_bar(artifacts.len() as u64);
39+
40+
for artifact in artifacts.iter_mut() {
41+
estimate(artifact);
42+
pb.inc(1);
43+
}
44+
pb.finish_and_clear();
45+
3446
for (i, artifact) in artifacts.iter().enumerate() {
3547
let rel_path =
3648
artifact.path.strip_prefix(&path).unwrap_or(&artifact.path);
3749
let size_display = match &artifact.size {
38-
Size::UnknownSize => style(format!("unknown")).yellow(),
50+
Size::UnknownSize => style(format!("{}", artifact.size)).yellow(),
3951
Size::KnownSize(_) => style(format!("{}", artifact.size)).green(),
4052
};
4153

@@ -46,6 +58,13 @@ fn scan() -> io::Result<()> {
4658
size_display
4759
))?;
4860
}
61+
62+
term.write_line("")?;
63+
term.write_line(&format!(
64+
"{} Scan completed successfully",
65+
style("✓").green()
66+
))?;
67+
4968
Ok(())
5069
}
5170
}

0 commit comments

Comments
 (0)