From 690ca3ffdf67ea7301399889f525003c9b980fbf Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:15:54 -0400 Subject: [PATCH 1/9] bump indicatif from 0.16 to 0.17 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 076b9aa..1b146e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ zip = { version = "0.6", default-features = false, features = ["time"], optional either = { version = "1", optional = true } reqwest = { version = "0.11", default-features = false, features = ["blocking", "json"] } hyper = "0.14" -indicatif = "0.16" +indicatif = "0.17" quick-xml = "0.22" regex = "1" log = "0.4" From 2747fc3e3866b1968adaa312835c10571415416c Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:30:37 -0400 Subject: [PATCH 2/9] Instead of ProgressStyle, use separate progress_template and progress_chars strings so we can still derive Debug, as ProgressStyle in indicatif 0.17 does not implement debug anymore with its progresstracker --- src/lib.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 35742ba..0fef5ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -607,7 +607,8 @@ pub struct Download { show_progress: bool, url: String, headers: reqwest::header::HeaderMap, - progress_style: ProgressStyle, + progress_template: String, + progress_chars: String, } impl Download { /// Specify download url @@ -616,9 +617,8 @@ impl Download { show_progress: false, url: url.to_owned(), headers: reqwest::header::HeaderMap::new(), - progress_style: ProgressStyle::default_bar() - .template("[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}") - .progress_chars("=>-"), + progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}".to_string(), + progress_chars: "=>-".to_string(), } } @@ -629,8 +629,9 @@ impl Download { } /// Set the progress style - pub fn set_progress_style(&mut self, progress_style: ProgressStyle) -> &mut Self { - self.progress_style = progress_style; + pub fn set_progress_style(&mut self, progress_template: String, progress_chars: String) -> &mut Self { + self.progress_template = progress_template; + self.progress_chars = progress_chars; self } @@ -699,7 +700,11 @@ impl Download { let mut downloaded = 0; let mut bar = if show_progress { let pb = ProgressBar::new(size); - pb.set_style(self.progress_style.clone()); + pb.set_style( + ProgressStyle::default_bar() + .template(&self.progress_template).unwrap() + .progress_chars(&self.progress_chars) + ); Some(pb) } else { From 224887b8641ffd367942e11bc5f9ea8d5e49c05c Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:31:38 -0400 Subject: [PATCH 3/9] change update to use progress_template and progress_chars --- src/update.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/update.rs b/src/update.rs index 5dbd1cc..b720722 100644 --- a/src/update.rs +++ b/src/update.rs @@ -1,4 +1,3 @@ -use indicatif::ProgressStyle; use reqwest::{self, header}; use std::fs; #[cfg(not(windows))] @@ -104,8 +103,11 @@ pub trait ReleaseUpdate { /// Flag indicating if the user shouldn't be prompted to confirm an update fn no_confirm(&self) -> bool; - /// Styling for progress information if `show_download_progress` is set (see `indicatif::ProgressStyle`) - fn progress_style(&self) -> Option; + // message template to use if `show_download_progress` is set (see `indicatif::ProgressStyle`) + fn progress_template(&self) -> String; + + // progress_chars to use if `show_download_progress` is set (see `indicatif::ProgressStyle`) + fn progress_chars(&self) -> String; /// Authorisation token for communicating with backend fn auth_token(&self) -> Option; @@ -218,9 +220,8 @@ pub trait ReleaseUpdate { download.set_headers(headers); download.show_progress(self.show_download_progress()); - if let Some(ref progress_style) = self.progress_style() { - download.set_progress_style(progress_style.clone()); - } + download.progress_template = self.progress_template(); + download.progress_chars = self.progress_chars(); download.download_to(&mut tmp_archive)?; From 506aee7a84e7192047aec38ff85abf9ebdbe91e2 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:31:49 -0400 Subject: [PATCH 4/9] update github backend --- src/backends/github.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/backends/github.rs b/src/backends/github.rs index df3dcc5..ae50044 100644 --- a/src/backends/github.rs +++ b/src/backends/github.rs @@ -4,7 +4,6 @@ GitHub releases use std::env::{self, consts::EXE_SUFFIX}; use std::path::{Path, PathBuf}; -use indicatif::ProgressStyle; use reqwest::{self, header}; use crate::backends::find_rel_next_link; @@ -238,7 +237,8 @@ pub struct UpdateBuilder { no_confirm: bool, current_version: Option, target_version: Option, - progress_style: Option, + progress_template: String, + progress_chars: String, auth_token: Option, custom_url: Option, } @@ -346,8 +346,9 @@ impl UpdateBuilder { } /// Toggle download progress bar, defaults to `off`. - pub fn set_progress_style(&mut self, progress_style: ProgressStyle) -> &mut Self { - self.progress_style = Some(progress_style); + pub fn set_progress_style(&mut self, progress_template: String, progress_chars: String) -> &mut Self { + self.progress_template = progress_template; + self.progress_chars = progress_chars; self } @@ -419,7 +420,8 @@ impl UpdateBuilder { }, target_version: self.target_version.as_ref().map(|v| v.to_owned()), show_download_progress: self.show_download_progress, - progress_style: self.progress_style.clone(), + progress_template: self.progress_template.clone(), + progress_chars: self.progress_chars.clone(), show_output: self.show_output, no_confirm: self.no_confirm, auth_token: self.auth_token.clone(), @@ -442,7 +444,8 @@ pub struct Update { show_download_progress: bool, show_output: bool, no_confirm: bool, - progress_style: Option, + progress_template: String, + progress_chars: String, auth_token: Option, custom_url: Option, } @@ -543,8 +546,12 @@ impl ReleaseUpdate for Update { self.no_confirm } - fn progress_style(&self) -> Option { - self.progress_style.clone() + fn progress_template(&self) -> String { + self.progress_template.to_owned() + } + + fn progress_chars(&self) -> String { + self.progress_chars.to_owned() } fn auth_token(&self) -> Option { @@ -566,7 +573,8 @@ impl Default for UpdateBuilder { no_confirm: false, current_version: None, target_version: None, - progress_style: None, + progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}".to_string(), + progress_chars: "=>-".to_string(), auth_token: None, custom_url: None, } From a13a0201f985a9848e02a3c4a482b369c4dfedfd Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:31:59 -0400 Subject: [PATCH 5/9] update gitlab backend --- src/backends/gitlab.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/backends/gitlab.rs b/src/backends/gitlab.rs index 656d23b..cad43a3 100644 --- a/src/backends/gitlab.rs +++ b/src/backends/gitlab.rs @@ -4,7 +4,6 @@ Gitlab releases use std::env::{self, consts::EXE_SUFFIX}; use std::path::{Path, PathBuf}; -use indicatif::ProgressStyle; use reqwest::{self, header}; use crate::backends::find_rel_next_link; @@ -222,7 +221,8 @@ pub struct UpdateBuilder { no_confirm: bool, current_version: Option, target_version: Option, - progress_style: Option, + progress_template: String, + progress_chars: String, auth_token: Option, } @@ -328,9 +328,10 @@ impl UpdateBuilder { self } - /// Toggle download progress bar, defaults to `off`. - pub fn set_progress_style(&mut self, progress_style: ProgressStyle) -> &mut Self { - self.progress_style = Some(progress_style); + /// Set download progress style. + pub fn set_progress_style(&mut self, progress_template: String, progress_chars: String) -> &mut Self { + self.progress_template = progress_template; + self.progress_chars = progress_chars; self } @@ -402,7 +403,8 @@ impl UpdateBuilder { }, target_version: self.target_version.as_ref().map(|v| v.to_owned()), show_download_progress: self.show_download_progress, - progress_style: self.progress_style.clone(), + progress_template: self.progress_template.clone(), + progress_chars: self.progress_chars.clone(), show_output: self.show_output, no_confirm: self.no_confirm, auth_token: self.auth_token.clone(), @@ -424,7 +426,8 @@ pub struct Update { show_download_progress: bool, show_output: bool, no_confirm: bool, - progress_style: Option, + progress_template: String, + progress_chars: String, auth_token: Option, } impl Update { @@ -515,8 +518,12 @@ impl ReleaseUpdate for Update { self.no_confirm } - fn progress_style(&self) -> Option { - self.progress_style.clone() + fn progress_template(&self) -> String { + self.progress_template.to_owned() + } + + fn progress_chars(&self) -> String { + self.progress_chars.to_owned() } fn auth_token(&self) -> Option { @@ -538,7 +545,8 @@ impl Default for UpdateBuilder { no_confirm: false, current_version: None, target_version: None, - progress_style: None, + progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}".to_string(), + progress_chars: "=>-".to_string(), auth_token: None, } } From 46eb7068101745c5491737925f0ee2b1372a0c18 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:32:08 -0400 Subject: [PATCH 6/9] update s3 backend --- src/backends/s3.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/backends/s3.rs b/src/backends/s3.rs index 502815e..d5c2501 100644 --- a/src/backends/s3.rs +++ b/src/backends/s3.rs @@ -7,7 +7,6 @@ use crate::{ update::{Release, ReleaseAsset, ReleaseUpdate}, version::bump_is_greater, }; -use indicatif::ProgressStyle; use quick_xml::events::Event; use quick_xml::Reader; use regex::Regex; @@ -154,7 +153,8 @@ pub struct UpdateBuilder { no_confirm: bool, current_version: Option, target_version: Option, - progress_style: Option, + progress_template: String, + progress_chars: String, auth_token: Option, } @@ -174,7 +174,8 @@ impl Default for UpdateBuilder { no_confirm: false, current_version: None, target_version: None, - progress_style: None, + progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}".to_string(), + progress_chars: "=>-".to_string(), auth_token: None, } } @@ -292,9 +293,10 @@ impl UpdateBuilder { self } - /// Toggle download progress bar, defaults to `off`. - pub fn set_progress_style(&mut self, progress_style: ProgressStyle) -> &mut Self { - self.progress_style = Some(progress_style); + /// Set download progress style. + pub fn set_progress_style(&mut self, progress_template: String, progress_chars: String) -> &mut Self { + self.progress_template = progress_template; + self.progress_chars = progress_chars; self } @@ -358,7 +360,8 @@ impl UpdateBuilder { }, target_version: self.target_version.as_ref().map(|v| v.to_owned()), show_download_progress: self.show_download_progress, - progress_style: self.progress_style.clone(), + progress_template: self.progress_template.clone(), + progress_chars: self.progress_chars.clone(), show_output: self.show_output, no_confirm: self.no_confirm, auth_token: self.auth_token.clone(), @@ -382,7 +385,8 @@ pub struct Update { show_download_progress: bool, show_output: bool, no_confirm: bool, - progress_style: Option, + progress_template: String, + progress_chars: String, auth_token: Option, } @@ -477,8 +481,12 @@ impl ReleaseUpdate for Update { self.no_confirm } - fn progress_style(&self) -> Option { - self.progress_style.clone() + fn progress_template(&self) -> String { + self.progress_template.to_owned() + } + + fn progress_chars(&self) -> String { + self.progress_chars.to_owned() } fn auth_token(&self) -> Option { From e903a6aaf059e9bc89649a4ee63820d89bd96d89 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:33:20 -0400 Subject: [PATCH 7/9] rustfmt --- src/backends/github.rs | 9 +++++++-- src/backends/gitlab.rs | 9 +++++++-- src/backends/s3.rs | 9 +++++++-- src/lib.rs | 16 +++++++++++----- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/backends/github.rs b/src/backends/github.rs index ae50044..c9ba678 100644 --- a/src/backends/github.rs +++ b/src/backends/github.rs @@ -346,7 +346,11 @@ impl UpdateBuilder { } /// Toggle download progress bar, defaults to `off`. - pub fn set_progress_style(&mut self, progress_template: String, progress_chars: String) -> &mut Self { + pub fn set_progress_style( + &mut self, + progress_template: String, + progress_chars: String, + ) -> &mut Self { self.progress_template = progress_template; self.progress_chars = progress_chars; self @@ -573,7 +577,8 @@ impl Default for UpdateBuilder { no_confirm: false, current_version: None, target_version: None, - progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}".to_string(), + progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}" + .to_string(), progress_chars: "=>-".to_string(), auth_token: None, custom_url: None, diff --git a/src/backends/gitlab.rs b/src/backends/gitlab.rs index cad43a3..688ce3b 100644 --- a/src/backends/gitlab.rs +++ b/src/backends/gitlab.rs @@ -329,7 +329,11 @@ impl UpdateBuilder { } /// Set download progress style. - pub fn set_progress_style(&mut self, progress_template: String, progress_chars: String) -> &mut Self { + pub fn set_progress_style( + &mut self, + progress_template: String, + progress_chars: String, + ) -> &mut Self { self.progress_template = progress_template; self.progress_chars = progress_chars; self @@ -545,7 +549,8 @@ impl Default for UpdateBuilder { no_confirm: false, current_version: None, target_version: None, - progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}".to_string(), + progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}" + .to_string(), progress_chars: "=>-".to_string(), auth_token: None, } diff --git a/src/backends/s3.rs b/src/backends/s3.rs index d5c2501..3c0dcd9 100644 --- a/src/backends/s3.rs +++ b/src/backends/s3.rs @@ -174,7 +174,8 @@ impl Default for UpdateBuilder { no_confirm: false, current_version: None, target_version: None, - progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}".to_string(), + progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}" + .to_string(), progress_chars: "=>-".to_string(), auth_token: None, } @@ -294,7 +295,11 @@ impl UpdateBuilder { } /// Set download progress style. - pub fn set_progress_style(&mut self, progress_template: String, progress_chars: String) -> &mut Self { + pub fn set_progress_style( + &mut self, + progress_template: String, + progress_chars: String, + ) -> &mut Self { self.progress_template = progress_template; self.progress_chars = progress_chars; self diff --git a/src/lib.rs b/src/lib.rs index 0fef5ba..cea8e9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -617,7 +617,8 @@ impl Download { show_progress: false, url: url.to_owned(), headers: reqwest::header::HeaderMap::new(), - progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}".to_string(), + progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}" + .to_string(), progress_chars: "=>-".to_string(), } } @@ -629,7 +630,11 @@ impl Download { } /// Set the progress style - pub fn set_progress_style(&mut self, progress_template: String, progress_chars: String) -> &mut Self { + pub fn set_progress_style( + &mut self, + progress_template: String, + progress_chars: String, + ) -> &mut Self { self.progress_template = progress_template; self.progress_chars = progress_chars; self @@ -702,9 +707,10 @@ impl Download { let pb = ProgressBar::new(size); pb.set_style( ProgressStyle::default_bar() - .template(&self.progress_template).unwrap() - .progress_chars(&self.progress_chars) - ); + .template(&self.progress_template) + .unwrap() + .progress_chars(&self.progress_chars), + ); Some(pb) } else { From 3948830c34ce72befc8c727cf9abed6b5a994abd Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:41:30 -0400 Subject: [PATCH 8/9] use expect --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index cea8e9a..45c4c4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -708,7 +708,7 @@ impl Download { pb.set_style( ProgressStyle::default_bar() .template(&self.progress_template) - .unwrap() + .expect("set ProgressStyle template failed") .progress_chars(&self.progress_chars), ); From ada335e0fa8906d6c7c33becdcbefb42ff96176b Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:57:56 -0400 Subject: [PATCH 9/9] use const DEFAULT_PROGRESS_TEMPLATE & DEFAULT_PROGRESS_CHARS --- src/backends/github.rs | 8 ++++---- src/backends/gitlab.rs | 6 +++--- src/backends/s3.rs | 6 +++--- src/lib.rs | 9 ++++++--- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/backends/github.rs b/src/backends/github.rs index c9ba678..d5807ff 100644 --- a/src/backends/github.rs +++ b/src/backends/github.rs @@ -11,6 +11,7 @@ use crate::{ errors::*, get_target, update::{Release, ReleaseAsset, ReleaseUpdate}, + DEFAULT_PROGRESS_CHARS, DEFAULT_PROGRESS_TEMPLATE, }; impl ReleaseAsset { @@ -345,7 +346,7 @@ impl UpdateBuilder { self } - /// Toggle download progress bar, defaults to `off`. + /// Set download progress style. pub fn set_progress_style( &mut self, progress_template: String, @@ -577,9 +578,8 @@ impl Default for UpdateBuilder { no_confirm: false, current_version: None, target_version: None, - progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}" - .to_string(), - progress_chars: "=>-".to_string(), + progress_template: DEFAULT_PROGRESS_TEMPLATE.to_string(), + progress_chars: DEFAULT_PROGRESS_CHARS.to_string(), auth_token: None, custom_url: None, } diff --git a/src/backends/gitlab.rs b/src/backends/gitlab.rs index 688ce3b..6e4f89a 100644 --- a/src/backends/gitlab.rs +++ b/src/backends/gitlab.rs @@ -11,6 +11,7 @@ use crate::{ errors::*, get_target, update::{Release, ReleaseAsset, ReleaseUpdate}, + DEFAULT_PROGRESS_CHARS, DEFAULT_PROGRESS_TEMPLATE, }; impl ReleaseAsset { @@ -549,9 +550,8 @@ impl Default for UpdateBuilder { no_confirm: false, current_version: None, target_version: None, - progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}" - .to_string(), - progress_chars: "=>-".to_string(), + progress_template: DEFAULT_PROGRESS_TEMPLATE.to_string(), + progress_chars: DEFAULT_PROGRESS_CHARS.to_string(), auth_token: None, } } diff --git a/src/backends/s3.rs b/src/backends/s3.rs index 3c0dcd9..e0e8f37 100644 --- a/src/backends/s3.rs +++ b/src/backends/s3.rs @@ -6,6 +6,7 @@ use crate::{ get_target, update::{Release, ReleaseAsset, ReleaseUpdate}, version::bump_is_greater, + DEFAULT_PROGRESS_CHARS, DEFAULT_PROGRESS_TEMPLATE, }; use quick_xml::events::Event; use quick_xml::Reader; @@ -174,9 +175,8 @@ impl Default for UpdateBuilder { no_confirm: false, current_version: None, target_version: None, - progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}" - .to_string(), - progress_chars: "=>-".to_string(), + progress_template: DEFAULT_PROGRESS_TEMPLATE.to_string(), + progress_chars: DEFAULT_PROGRESS_CHARS.to_string(), auth_token: None, } } diff --git a/src/lib.rs b/src/lib.rs index 45c4c4f..fbfa3d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -150,6 +150,10 @@ pub mod errors; pub mod update; pub mod version; +pub const DEFAULT_PROGRESS_TEMPLATE: &str = + "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}"; +pub const DEFAULT_PROGRESS_CHARS: &str = "=>-"; + use errors::*; /// Get the current target triple. @@ -617,9 +621,8 @@ impl Download { show_progress: false, url: url.to_owned(), headers: reqwest::header::HeaderMap::new(), - progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}" - .to_string(), - progress_chars: "=>-".to_string(), + progress_template: DEFAULT_PROGRESS_TEMPLATE.to_string(), + progress_chars: DEFAULT_PROGRESS_CHARS.to_string(), } }