From 8b83c97b7b4611d44a45bfc6a04a200b2ff4c5b9 Mon Sep 17 00:00:00 2001 From: Mitchell Berendhuysen Date: Fri, 2 Sep 2022 11:48:01 +0200 Subject: [PATCH] added support for tag_name once downloaded --- src/model/release.rs | 2 +- src/sync/download.rs | 2 ++ src/sync/install.rs | 15 ++++++++------- src/sync/progress.rs | 17 +++++++++++------ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/model/release.rs b/src/model/release.rs index fd43673..7fd39b8 100644 --- a/src/model/release.rs +++ b/src/model/release.rs @@ -2,7 +2,7 @@ use serde::Deserialize; #[derive(Deserialize, Debug)] pub struct Release { - // tag_name: String, + pub tag_name: String, pub assets: Vec, } diff --git a/src/sync/download.rs b/src/sync/download.rs index cf90381..ecb897f 100644 --- a/src/sync/download.rs +++ b/src/sync/download.rs @@ -20,6 +20,7 @@ pub struct Downloader<'a> { pub struct DownloadInfo { pub archive_path: PathBuf, pub asset_name: String, + pub tag_name: String, } impl<'a> Downloader<'a> { @@ -106,6 +107,7 @@ impl<'a> Downloader<'a> { Ok(DownloadInfo { archive_path, asset_name: asset.name.clone(), + tag_name: release.tag_name, }) } } diff --git a/src/sync/install.rs b/src/sync/install.rs index b72ace3..e03cc95 100644 --- a/src/sync/install.rs +++ b/src/sync/install.rs @@ -44,14 +44,15 @@ impl Installer { let pb_msg = self.sync_progress.create_message_bar(tool_name); match configure_tool(tool_name, config_asset) { - Tool::Known(tool_info) => { - if let Err(e) = self.sync_single_tool(&tool_info, &pb_msg) { + Tool::Known(tool_info) => match self.sync_single_tool(&tool_info, &pb_msg) { + Ok(tag_name) => { + self.sync_progress.success(pb_msg, tool_name, &tag_name); + } + Err(e) => { self.sync_progress .failure(pb_msg, tool_name, format!("[error] {}", e)); - } else { - self.sync_progress.success(pb_msg, tool_name); } - } + }, Tool::Error(e) => { self.sync_progress.failure(pb_msg, tool_name, e.display()); } @@ -62,7 +63,7 @@ impl Installer { &self, tool_info: &ToolInfo, pb_msg: &ProgressBar, - ) -> Result<(), Box> { + ) -> Result> { match tool_info.asset_name.get_name_by_os() { None => Err( "Don't know the asset name for this OS: specify it explicitly in the config".into(), @@ -93,7 +94,7 @@ impl Installer { Err(unpack_err) => Err(unpack_err.display().into()), Ok(tool_path) => { copy_file(tool_path, &self.store_directory, &tool_info.exe_name)?; - Ok(()) + Ok(download_info.tag_name) } }, } diff --git a/src/sync/progress.rs b/src/sync/progress.rs index 97ec926..bbf30f3 100644 --- a/src/sync/progress.rs +++ b/src/sync/progress.rs @@ -25,8 +25,13 @@ impl SyncProgress { } } - fn fmt_prefix(&self, emoji: Emoji, tool_name: &str) -> String { - let aligned_tool = format!("{:width$}", tool_name, width = self.max_tool_size); + fn fmt_prefix(&self, emoji: Emoji, tool_name: &str, tag_name: &str) -> String { + let aligned_tool = format!( + "{:width$} {:<8}", + tool_name, + tag_name, + width = self.max_tool_size + ); format!("{}{}", emoji, aligned_tool) } @@ -37,7 +42,7 @@ impl SyncProgress { self.multi_progress.add( ProgressBar::new(100) .with_style(message_style) - .with_prefix(self.fmt_prefix(PROCESS, tool_name)), + .with_prefix(self.fmt_prefix(PROCESS, tool_name, "")), ) } @@ -53,8 +58,8 @@ impl SyncProgress { pb.finish_and_clear() } - pub fn success(&self, pb: ProgressBar, tool_name: &str) { - pb.set_prefix(self.fmt_prefix(SUCCESS, tool_name)); + pub fn success(&self, pb: ProgressBar, tool_name: &str, tag_name: &str) { + pb.set_prefix(self.fmt_prefix(SUCCESS, tool_name, tag_name)); let success_msg = format!("{}", style("Completed!").bold().green()); pb.set_message(success_msg); @@ -62,7 +67,7 @@ impl SyncProgress { } pub fn failure(&self, pb: ProgressBar, tool_name: &str, err_msg: String) { - pb.set_prefix(self.fmt_prefix(FAILURE, tool_name)); + pb.set_prefix(self.fmt_prefix(FAILURE, tool_name, "")); let failure_msg = format!("{}", style(err_msg).red()); pb.set_message(failure_msg);