diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-02-29 19:44:06 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-02-29 19:44:09 +0100 |
commit | f5c014160ccb8584c796cce484196842ae2455cc (patch) | |
tree | e1ee7e0fb2b00066d7eadff878bfbcf9bafd36a2 | |
parent | 1d0e3aa8ba3050f47657c52b96f4cee84e90864c (diff) |
Include progressbar in iterator
indicatif got a new feature where the iterator can be used directly with
the ProgressBar object. Change the code to use that.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | bin/core/imag-diagnostics/src/lib.rs | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/bin/core/imag-diagnostics/src/lib.rs b/bin/core/imag-diagnostics/src/lib.rs index 1b3ec62b..4b6e53c4 100644 --- a/bin/core/imag-diagnostics/src/lib.rs +++ b/bin/core/imag-diagnostics/src/lib.rs @@ -57,7 +57,7 @@ use libimagentrylink::linkable::Linkable; use toml::Value; use toml_query::read::TomlValueReadExt; -use indicatif::{ProgressBar, ProgressStyle}; +use indicatif::{ProgressIterator, ProgressBar, ProgressStyle}; use failure::Fallible as Result; use failure::err_msg; use clap::App; @@ -122,15 +122,15 @@ impl ImagApplication for ImagDiagnostics { ProgressStyle::default_spinner() }; - let spinner = ProgressBar::new_spinner(); - spinner.enable_steady_tick(100); - spinner.set_style(style); - spinner.set_message("Accumulating data"); + let progressbar = ProgressBar::new(100); + progressbar.set_style(style); + progressbar.set_message("Accumulating data"); let diags = rt.store() .entries()? .into_get_iter() .map_inner_ok_or_else(|| err_msg("Unable to get entry")) + .progress_with(progressbar) .and_then_ok(|e| { let diag = Diagnostic::for_entry(&e); debug!("Diagnostic for '{:?}' = {:?}", e.get_location(), diag); @@ -139,16 +139,15 @@ impl ImagApplication for ImagDiagnostics { }) .collect::<Result<Vec<_>>>()?; - spinner.finish(); - let n = diags.len(); - let progress = ProgressBar::new(n as u64); - let style = if let Some(template) = template { + let n = diags.len(); + let progressbar = ProgressBar::new(n as u64); + let style = if let Some(template) = template { ProgressStyle::default_bar().template(&template) } else { ProgressStyle::default_bar() }; - progress.set_style(style); - progress.set_message("Calculating stats"); + progressbar.set_style(style); + progressbar.set_message("Calculating stats"); let mut version_counts : BTreeMap<String, usize> = BTreeMap::new(); let mut sum_header_sections = 0; @@ -161,7 +160,7 @@ impl ImagApplication for ImagDiagnostics { let mut num_links = 0; let mut max_links : Option<(usize, StoreId)> = None; - for diag in diags.iter() { + for diag in diags.iter().progress_with(progressbar) { sum_header_sections += diag.header_sections; sum_bytecount_content += diag.bytecount_content; sum_overall_byte_size += diag.overall_byte_size; @@ -192,11 +191,8 @@ impl ImagApplication for ImagDiagnostics { } } - progress.inc(1); } - progress.finish(); - let mut out = rt.stdout(); writeln!(out, "imag version {}", { env!("CARGO_PKG_VERSION") })?; |