Skip to content

Commit 64feb48

Browse files
authored
admin/upload_index: Use indicatif for progress reporting (#4836)
1 parent cca976d commit 64feb48

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

Cargo.lock

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ hex = "=0.4.3"
6161
http = "=0.2.7"
6262
hyper = { version = "=0.14.19", features = ["client", "http1"] }
6363
indexmap = { version = "=1.8.2", features = ["serde-1"] }
64+
indicatif = "=0.16.2"
6465
ipnetwork = "=0.19.0"
6566
tikv-jemallocator = { version = "=0.5.0", features = ['unprefixed_malloc_on_supported_platforms', 'profiling'] }
6667
lettre = { version = "=0.10.0-rc.6", default-features = false, features = ["file-transport", "smtp-transport", "native-tls", "hostname", "builder"] }

src/admin/upload_index.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::time::{Duration, Instant};
2-
31
use crate::admin::dialoguer;
42
use cargo_registry_index::{Repository, RepositoryConfig};
3+
use indicatif::{ProgressBar, ProgressIterator, ProgressStyle};
54
use reqwest::blocking::Client;
65

76
use crate::config;
@@ -33,23 +32,18 @@ pub fn run(opts: Opts) -> anyhow::Result<()> {
3332
return Ok(());
3433
}
3534

36-
let mut progress_update_time = Instant::now();
37-
for (i, file) in files.iter().enumerate() {
35+
let pb = ProgressBar::new(files.len() as u64);
36+
pb.set_style(ProgressStyle::default_bar().template("{bar:60} ({pos}/{len}, ETA {eta})"));
37+
38+
for file in files.iter().progress_with(pb) {
3839
let crate_name = file.file_name().unwrap().to_str().unwrap();
3940
let path = repo.index_file(crate_name);
4041
if !path.exists() {
41-
println!("skipping file `{}`", crate_name);
4242
continue;
4343
}
44+
4445
let contents = std::fs::read_to_string(&path)?;
4546
uploader.upload_index(&client, crate_name, contents)?;
46-
47-
// Print a progress update every 10 seconds.
48-
let now = Instant::now();
49-
if now - progress_update_time > Duration::from_secs(10) {
50-
progress_update_time = now;
51-
println!("uploading {}/{}", i, files.len());
52-
}
5347
}
5448

5549
println!(

0 commit comments

Comments
 (0)