Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#49] Specify which version of the tool was actually downloaded #60

Merged
merged 2 commits into from
Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/model/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::Deserialize;

#[derive(Deserialize, Debug)]
pub struct Release {
// tag_name: String,
pub tag_name: String,
pub assets: Vec<Asset>,
}

Expand Down
2 changes: 2 additions & 0 deletions src/sync/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -106,6 +107,7 @@ impl<'a> Downloader<'a> {
Ok(DownloadInfo {
archive_path,
asset_name: asset.name.clone(),
tag_name: release.tag_name,
})
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/sync/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -62,7 +63,7 @@ impl Installer {
&self,
tool_info: &ToolInfo,
pb_msg: &ProgressBar,
) -> Result<(), Box<dyn Error>> {
) -> Result<String, Box<dyn Error>> {
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(),
Expand Down Expand Up @@ -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)
}
},
}
Expand Down
17 changes: 11 additions & 6 deletions src/sync/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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, "")),
)
}

Expand All @@ -53,16 +58,16 @@ 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);
pb.finish();
}

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);
Expand Down